samedi 26 juillet 2014

Java - la désérialisation par critères avec Jackson - Stack Overflow


I'll start of with a sample JSON:


{
"properties": {
"instance": 123,
"name": "foobar",
"someEntity": {
"id": "456",
"name": "example",
"type": "foo"
},
"notEntity": {
"x": 1,
"y": 2
}
}
}

Ultimately, I would like properties to be represented in Java as a Map<String, Object>. However, during deserialization, when a value is found to be a Map containing the keys id, name, and type, I want it to be represented by a specific Entity object.


Map<String, Object>:
"instance": (int) 123,
"uuid": (String) "foobar",
"someEntity": (Entity) <456, "example", "foo">,
"notEntity": (Map) <1, 2>

I'm wondering how best to instruct Jackson (version 1.9.2) to perform this sort of filtered (?) deserialization.



I'll start of with a sample JSON:


{
"properties": {
"instance": 123,
"name": "foobar",
"someEntity": {
"id": "456",
"name": "example",
"type": "foo"
},
"notEntity": {
"x": 1,
"y": 2
}
}
}

Ultimately, I would like properties to be represented in Java as a Map<String, Object>. However, during deserialization, when a value is found to be a Map containing the keys id, name, and type, I want it to be represented by a specific Entity object.


Map<String, Object>:
"instance": (int) 123,
"uuid": (String) "foobar",
"someEntity": (Entity) <456, "example", "foo">,
"notEntity": (Map) <1, 2>

I'm wondering how best to instruct Jackson (version 1.9.2) to perform this sort of filtered (?) deserialization.


0 commentaires:

Enregistrer un commentaire