Giter Site home page Giter Site logo

Comments (4)

Lars-Sommer avatar Lars-Sommer commented on June 10, 2024 1

Makes great sense, and it works ofc :)
Thanks alot! 🍺

from dart-json-mapper.

k-paxian avatar k-paxian commented on June 10, 2024 1

Wow, so generous, thank you so much appreciate that. All I can do for you is my pleasure, challenge me whenever you like

from dart-json-mapper.

Lars-Sommer avatar Lars-Sommer commented on June 10, 2024 1

This library is priceless, and your ability to help and sort out issues so fast is incredible!

from dart-json-mapper.

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

well, that should be the easy one, it's not obvious that constructor parameter actionType needs to be mapped to json field type, so you should tell it explicitly how to operate:

@JsonSerializable()
class TestModel {
  EActionType type = EActionType.None;

  TestModel(@JsonProperty(name: 'type') EActionType actionType) {
    type = actionType;
  }
}

This should do the trick, if not let me know.

In your case you have different field names, but there are more cases around that, like:

  • when the class field names matched to json fields it's an auto-mapping, obvious one so it works right away
  • the class has read-only field type and you can set it via constructor only, but you are giving constructor parameter same name type that case is not resolved automagically yet 😄
@jsonSerializable
class Model {
  EActionType _type = EActionType.None;
  EActionType get type {
    return _type;
  }

  Model(EActionType  type) {
    _type = type;
  }
}

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.