GithubHelp home page GithubHelp logo

Comments (7)

paolo-rossi avatar paolo-rossi commented on May 27, 2024

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.

AlexeyM123 avatar AlexeyM123 commented on May 27, 2024

Dear Paolo.
Thank you for your lib and your assistance.
I will try to test the solution.

from delphi-neon.

AlexeyM123 avatar AlexeyM123 commented on May 27, 2024

Dear Paolo
I tried TNeon.ValueToJSONString(TValue.From(rec))
A value of the nullable record member is omitted in JSON.

from delphi-neon.

paolo-rossi avatar paolo-rossi commented on May 27, 2024

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.

AlexeyM123 avatar AlexeyM123 commented on May 27, 2024

Dear Paolo
Maybe I misunderstand the issue.
I expect if nullable value is null the json will be
{
"Three": null
}

from delphi-neon.

paolo-rossi avatar paolo-rossi commented on May 27, 2024

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.

AlexeyM123 avatar AlexeyM123 commented on May 27, 2024

Dear Paolo
Thank you. Very appreciated

from delphi-neon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.