Last active
August 29, 2015 14:24
-
-
Save frsyuki/ffc003b44f64b1b3074e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.annotation.JsonValue; | |
import com.fasterxml.jackson.annotation.JsonCreator; | |
@MessagePackPolymorphicTypeStorage("csharp_types") | |
public class DictWithPersistentTypeInfo | |
{ | |
private final Map<String, Object> dict; | |
@JsonCreator | |
public MyDictWithPersistentTypeInfo(Map<String, Object> dict) | |
{ | |
this.dict = dict; | |
} | |
@JsonValue | |
public Map<String, Object> getDict() | |
{ | |
return dict; | |
} | |
} | |
public class MyClass | |
{ | |
private final String str1; | |
private final String str2; | |
... | |
} | |
DictWithPersistentTypeInfo src = new DictWithPersistentTypeInfo(ImmutableMap.of( | |
"myclass", MyClass.new("value1", "value2") | |
)); | |
data = MessgePack.pack(my); | |
// | |
// If @MessagePackPolymorphicTypeStorage("csharp_types") is NOT set: | |
// data = {"myclass": {"str1": "value1", "str2", "value2"}} | |
// | |
// If @MessagePackPolymorphicTypeStorage("csharp_types") is set: | |
// data = {"myclass": {"str1": "value1", "str2", "value2"}, "csharp_types": {"myclass": "MyClass"}} | |
// | |
DictWithPersistentTypeInfo dst = new ObjectMapper().readValue(, DictWithPersistentTypeInfo.class); | |
// | |
// If @MessagePackPolymorphicTypeStorage("csharp_types") is NOT set: | |
// dst.dict = {"myclass": {"str1": "value1", "str2", "value2"}} | |
// | |
// If @MessagePackPolymorphicTypeStorage("csharp_types") is set: | |
// dst.dict = {"myclass": new MyClass("value1", "value2")} | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment