Skip to content

Instantly share code, notes, and snippets.

@push-gists
Last active April 27, 2016 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save push-gists/a01f11981fd60fd42fd18397b31b8b21 to your computer and use it in GitHub Desktop.
Save push-gists/a01f11981fd60fd42fd18397b31b8b21 to your computer and use it in GitHub Desktop.
Provides a shared context for using Jackson
public enum JacksonContext {
INSTANCE;
private final CBORFactory factory = new CBORFactory();
private final ObjectMapper mapper = new ObjectMapper(factory);
public static Map<String, Object> jsonToMap(JSON json) throws IOException {
try (CBORParser parser = INSTANCE.factory.createParser(json.asInputStream())) {
return INSTANCE.mapper.readValue(parser, new TypeReference<Map<String, Object>>() { });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment