schmittjoh / serializer

Library for (de-)serializing data of any complexity (supports JSON, and XML)
http://jmsyst.com/libs/serializer
MIT License
2.33k stars 587 forks source link

deserialize mixed array #149

Open samsamm777 opened 11 years ago

samsamm777 commented 11 years ago

I have an array of mixed objects. Is it at all possible to de-serialize it back into their actual objects, rather than an array.

               "objects":[
                  {
                     "label":"Cambridge Blue",
                     "colour":{
                        "r":0.63,
                        "g":0.75,
                        "b":0.67
                     }
                  },
                  {
                     "name":"Wood_01",
                     "label":"Weathered Oak",
                     "transform":{
                        "rotation":0,
                        "offset_x":0,
                        "offset_y":0,
                        "scale":1
                     }
                  }
               ],
               "mutable":true,
               "position":2
            },
Tobion commented 10 years ago

You can use @Discriminator assuming the mixed types have a common parent class. If that's not the case, I don't see how and why it should be possible. It would definitely make more sense to use different properties for different types.