Coder Social home page Coder Social logo

Comments (4)

k-paxian avatar k-paxian commented on June 3, 2024

Can you illustrate your case with the failing unit test please? That way it would be more productive and fast to correct

from dart-json-mapper.

rxvincent avatar rxvincent commented on June 3, 2024

I have a base class with below statement

@jsonSerializable
@Json(discriminatorProperty: 'type')
abstract class BaseAction {
  String? type;
}

and then I have a class implement

@jsonSerializable
class ShowRectangleAction extends BaseAction {
  // properties
}

Serialize has no error but when I try to deserialize previous serialized json string. It lead to a JsonMapperSubtypeError error.

In my case, all validDiscriminators is null.

from dart-json-mapper.

rxvincent avatar rxvincent commented on June 3, 2024

In mapper.dart when deserialize, method _detectObjectType need to find a Type from _discriminatorToType map. Here, the discriminatorValue can get a correct class name. But the question is in_discriminatorToType. I can only find there is one method to update this map is _updateInternalMaps(). And only those class with jsonMeta.discriminatorValue != null would trigger _discriminatorToType.putIfAbsent to update this map.

from dart-json-mapper.

k-paxian avatar k-paxian commented on June 3, 2024

Please take a look at this issue. Probably it would be useful to rely on that as well. What do you think?

@jsonSerializable
@Json(discriminatorProperty: 'type')
abstract class BaseAction {
  @JsonProperty(ignore: true)
  Type get type => runtimeType;
}

Anyway, I'd love to see a test somewhere here which is illustrating your case

from dart-json-mapper.

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.