Created
December 8, 2015 21:18
-
-
Save pavolloffay/41eb9245064532fb4e90 to your computer and use it in GitHub Desktop.
Hawkular Bus serialization test
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
@Test | |
public void testA() throws Exception { | |
ObjectMapper objectMapper = new ObjectMapper(); | |
InventoryJacksonConfig.configure(objectMapper); | |
Query relationships = Query.filter().with(RelationWith.name("__inPrediction")).with(RelationWith.sourceOfType | |
(Tenant.class)).with(RelationWith.targetOfType(Metric.class)).get(); | |
String json = serialize(relationships, objectMapper); | |
Query queryFromJson = deserialize(json, Query.class, objectMapper); | |
} | |
private String serialize(Object object, ObjectMapper mapper) throws IOException { | |
StringWriter out = new StringWriter(); | |
JsonGenerator gen = mapper.getFactory().createGenerator(out); | |
gen.writeObject(object); | |
gen.close(); | |
out.close(); | |
return out.toString(); | |
} | |
private <T> T deserialize(String json, Class<T> type, ObjectMapper mapper) throws Exception { | |
JsonParser parser = mapper.getFactory().createParser(json); | |
return parser.readValueAs(type); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment