Comments (7)
Hello @AlexeyM123 ,
to serialize this type you can use this code:
var rec: TMyRecord;
var res := TNeon.ValueToJSONString(TValue.From<TMyRecord>(rec), config);
and to deserialize the JSON string into a variable rec
:
var rec := TNeon.JSONToValue<TMyRecord>(GetJson, config);
I hope that this helps you, I'm closing the issue but feel free to ask again.
Paolo.
from delphi-neon.
Dear Paolo.
Thank you for your lib and your assistance.
I will try to test the solution.
from delphi-neon.
Dear Paolo
I tried TNeon.ValueToJSONString(TValue.From(rec))
A value of the nullable record member is omitted in JSON.
from delphi-neon.
Alexey,
strange, I'm testing right now and the value of the field "Three" gets serialized (if it's not null)
I attach my test project (please rename it in TestIssue_88.dpr)
TestIssue_88.txt
Paolo.
from delphi-neon.
Dear Paolo
Maybe I misunderstand the issue.
I expect if nullable value is null the json will be
{
"Three": null
}
from delphi-neon.
Hello Alexey,
Ok now I see...
I will give you the explanation and a simple workaround, but I'm thinking to change that in a next release:
[Explanation]
The problem lies in the definition of the IncludeIf enum (Neon.Core.Attributes.pas line 92), as you can see the first enum (the default) is NotNull
so all the properties/fields have a default of NotNull
when serializing/deserializing meaning that Neon will skip that property/field if nil
.
Now, it's probably better to have Always as default for props/fields but this will be a breaking change although I'm surely evaluating the change..
[Workaround]
Please annotate the Three
property with IncludeIf.Always like that:
[NeonInclude(IncludeIf.Always)]
Three: Nullable<integer>;
If and when I change the default then you can remove the attribute (but in your case it doesn't change the result)
Ciao,
Paolo.
from delphi-neon.
Dear Paolo
Thank you. Very appreciated
from delphi-neon.
Related Issues (20)
- How do I use Arrays and Records ? HOT 5
- ReadEnum should use TJSONBool HOT 1
- Wrong interpretation of [NeonInclude(IncludeIf.NotEmpty)] ? HOT 1
- Read static array issue HOT 1
- Not compatible with XE7 HOT 1
- Error Compilig TBase64 class
- Insufficient RTTI available HOT 1
- Unwanted behavior when deserializing empty strings or enums HOT 1
- Compiler warning for TRttiUtils.ForEachFieldWithAttribute<T> HOT 2
- Deserialising GUID to TGUID exception: "EInvalidCast" HOT 1
- Function 'TJSONUtils.GetValueBool' might be undefined
- Multithread - Access violation when a json is deserialized HOT 3
- we need a TNeon.Print with the param TJSONAncestor.TJSONOutputOptions
- request HOT 2
- Possible Issue with TJSONUtils.JSONToDate
- Multithreading is prone to problems HOT 1
- Can not Deserialize a Class with Arrays HOT 3
- Some code is HOT 1
- System.JSON.Serializers.TJsonSerializer performance is better than neon HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from delphi-neon.