Giter VIP home page Giter VIP logo

Comments (5)

chaowlert avatar chaowlert commented on May 18, 2024 1

I also have this issue. Problem is JObject contains internal setter like Parent, Next, Previous (which Mapster will translate type as class rather than primitive). Then, Mapster try to perform deep copy, but Parent, Next, Previous are JToken which is abstract. Currently, I solve this problem by using MapWith to perform direct copy.

TypeAdapterConfig<JObject, JObject>.NewConfig().MapWith(src => src);
TypeAdapterConfig<JArray, JArray>.NewConfig().MapWith(src => src);
TypeAdapterConfig<JValue, JValue>.NewConfig().MapWith(src => src);
TypeAdapterConfig<JToken, JToken>.NewConfig().MapWith(src => src);

from mapster.

centur avatar centur commented on May 18, 2024

You can close this issue if you want, search should help others who may stumble over the same problem

from mapster.

chaowlert avatar chaowlert commented on May 18, 2024

Do you have idea to improve this? Will it help if I add another method explicitly like TypeAdapterConfig.Default.AddPrimitiveType<JObject>()? If you have better name or better idea, pls suggest.

from mapster.

centur avatar centur commented on May 18, 2024

I actually like the syntax we currently have: TypeAdapterConfig<JArray, JArray>.NewConfig().MapWith(src => src);.
It's clear and explicit and it doesn't add any extra methods to know about, so user uses the same, already known grammar set for this library. Also it helps when you're searching for a particular mapping - I can search for all lines using same pattern - TypeAdapterConfig<JValue - finds all mappings from JValue
and TypeAdapterConfig<[^,],JValue> finds me all mappings to JValue.

It may be worth to put an extra line or two in docs about this, as I'm sure that many users map objects that are coming from API (cross-domain boundary) e.g. in Json or XML or other cross-platform format.

from mapster.

chaowlert avatar chaowlert commented on May 18, 2024

I just added a couple of lines for MapWith in doc.

from mapster.

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.