Can I instantiate a superclass and have a particular subclass be instantiated based on the parameters supplied

后端 未结 2 1121
傲寒
傲寒 2020-12-11 12:56

I am using Google\'s GSON package http://code.google.com/p/google-gson/

I am converting JSON to Java.

I have this fragment of code where I do the conversion.

相关标签:
2条回答
  • 2020-12-11 13:41

    Gson does not currently have a simple mechanism for polymorphic deserialization, other than implementing custom deserialization processing. The next release looks like it will provide a built-in solution.

    Previous StackOverflow.com Questions And Answers (Some With Examples) On This Topic:

    • Deserialising a generic with unknown compile time type where a field indicates the type
    • Parse JSON with no specific structure for a field with GSON
    • json object serialization/deserialization using google gson
    • Polymorphism with gson
    0 讨论(0)
  • 2020-12-11 13:43

    Sounds like you want to create a custom deserializer if you need to check the values, or an instance creator if you only need to create an instance based on type.

    0 讨论(0)
提交回复
热议问题