Giter Club home page Giter Club logo

Comments (6)

DavidArno avatar DavidArno commented on July 1, 2024

Oh, that's an interesting one. Bit embarrassing to admit, but it has never occurred to me that someone might want to serialise a union!

So the honest answer is that Succinc<T> has no support currently, but it's certainly something that can be added.

from succinct.

rubiktubik avatar rubiktubik commented on July 1, 2024

Too bad :-(
Then in the moment i need a way around it :-)

from succinct.

DavidArno avatar DavidArno commented on July 1, 2024

@rubiktubik,

Quick update on this.

I don't want to make Succinc<T> itself dependent on JSON.Net, therefore I'll create a new SuccincT.JSON nuget package, which will include Succinc<T> itself and support for serializing union types to JSON. That serialization will likely be achieved via custom JsonConverter and ContractResolver classes, rather than by annotating the types with JSON.Net specific attributes.

This'll mean you'd have to do something like:

string json = JsonConvert.SerializeObject(
    dataIncludingUnions,
    Formatting.Indented,
    new JsonSerializerSettings { ContractResolver = new SuccinctContractResolver() });

ie, whenever you need to serialize/deserialize any JSON that would include a union, you'd have to specify the custom ContractResolver class. Would that work for you?

from succinct.

rubiktubik avatar rubiktubik commented on July 1, 2024

Yes!, that would be perfectly work!
I've seen similar approaches at other libraries.

Thank you for your effort.

from succinct.

DavidArno avatar DavidArno commented on July 1, 2024

Tasks required to complete this work:

  • Converter for Option<>
  • Converter for Union<,>
  • Converter for Union<,,>
  • Converter for Union<,,,>
  • Converter for ValueOrError
  • Converter for Maybe<>
  • Converter for None
  • Converter for Unit
  • ContractResolver that handles the above types
  • Wiki updates to document how to use the converters and ContractResolver.
  • Create new nuget package that contains Succinc<T> and the JSON converters
  • Publish new nuget packages

from succinct.

DavidArno avatar DavidArno commented on July 1, 2024

Version 2.2.0 of SuccincT.JSON is now available on nuget, which supplies JSON serialization support for Succinc<T> types.

This is the first release, but the version number has been set to coincide with the compatible release of Succinc<T> itself.

Please see the JSON Serialization page for details of its use.

from succinct.

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.