Jackson HPPC serialization example


/ Published in: Java
Save to your folder(s)

(De-)serialising an HPPC map using the jackson HPPC module.


Copy this code and paste it in your HTML
  1. /*
  2. Project website:
  3. https://github.com/FasterXML/jackson-datatype-hppc
  4.  
  5. Maven:
  6. <dependency>
  7.   <groupId>com.fasterxml.jackson.datatype</groupId>
  8.   <artifactId>jackson-datatype-hppc</artifactId>
  9.   <version>2.0.0-RC1</version>
  10. </dependency>
  11. */
  12.  
  13. import com.carrotsearch.hppc.ObjectObjectOpenHashMap;
  14. import com.fasterxml.jackson.core.type.TypeReference;
  15. import com.fasterxml.jackson.databind.DeserializationFeature;
  16. import com.fasterxml.jackson.databind.ObjectMapper;
  17. import com.fasterxml.jackson.datatype.hppc.HppcModule;
  18.  
  19. // Serialize:
  20. ObjectObjectOpenHashMap<String, ObjectDoubleOpenHashMap<String>> mapStringMapStringDouble = new ObjectObjectOpenHashMap<String, ObjectDoubleOpenHashMap<String>>();
  21.  
  22. // fill map
  23.  
  24. ObjectMapper mapper = new ObjectMapper();
  25. mapper.registerModule(new HppcModule());
  26. mapper.writeValue(new FileOutputStream("filename-goes-here"), mapStringMapStringDouble);
  27.  
  28. // De-serialize:
  29. ObjectMapper mapper = new ObjectMapper();
  30. mapper.registerModule(new HppcModule());
  31. mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  32.  
  33. ObjectObjectOpenHashMap<String, ObjectDoubleOpenHashMap<String>> mapStringMapStringDouble = mapper.readValue(inputStream, new TypeReference<ObjectObjectOpenHashMap<String, ObjectDoubleOpenHashMap<String>>>() {});

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.