GPOUtils { public static GPOMutable deserialize(FieldsDescriptor fieldsDescriptor, JSONObject dpou) { GPOMutable gpo = new GPOMutable(fieldsDescriptor); @SuppressWarnings("unchecked") Iterator<String> itr = (Iterator<String>)dpou.keys(); while (itr.hasNext()) { String field = itr.next(); setFieldFromJSON(gpo, field, dpou); } return gpo; } private  GPOUtils(); @SuppressWarnings("unchecked") static Map<String, Type> buildTypeMap(JSONObject jo); static GPOMutable deserialize(FieldsDescriptor fieldsDescriptor, JSONObject dpou); static Map<String, Set<Object>> deserializeToMap(FieldsDescriptor fieldsDescriptor, JSONObject dpou); static void setFieldFromJSON(GPOMutable gpo, Type type, String field, JSONArray jo, int index); static void setFieldFromJSON(GPOMutable gpo, String field, JSONObject jo); static Object getFieldFromJSON(FieldsDescriptor fd, String field, JSONObject jo); static Object getFieldFromJSON(Type type, JSONArray ja, int index); static JSONObject serializeJSONObject(GPOMutable gpo, Fields fields, ResultFormatter resultFormatter); static JSONObject serializeJSONObject(GPOMutable gpo, ResultFormatter resultFormatter); static int serializedLength(GPOMutable gpo); static byte[] serialize(GPOMutable gpo, GPOByteArrayList byteArrayList); static byte[] serialize(GPOMutable gpo, Fields excludedFields); static GPOMutable deserialize(FieldsDescriptor fd, byte[] serializedGPO, MutableInt offset); static GPOMutable deserialize(FieldsDescriptor fieldsDescriptor, Fields excludedFields, byte[] serializedGPO,
      int offset); static String deserializeString(byte[] buffer, MutableInt offset); static void serializeString(String val, byte[] buffer, MutableInt offset); static byte[] serializeString(String val); static long deserializeLong(byte[] buffer, MutableInt offset); static void serializeLong(long val, byte[] buffer, MutableInt offset); static byte[] serializeLong(long val); static long deserializeLong(byte[] buffer); static double deserializeDouble(byte[] buffer, MutableInt offset); static void serializeDouble(double valD, byte[] buffer, MutableInt offset); static byte[] serializeDouble(double valD); static int deserializeInt(byte[] buffer, MutableInt offset); static int deserializeInt(byte[] buffer); static void serializeInt(int val, byte[] buffer, MutableInt offset); static byte[] serializeInt(int val); static float deserializeFloat(byte[] buffer, MutableInt offset); static void serializeFloat(float valf, byte[] buffer, MutableInt offset); static byte[] serializeFloat(float valf); static short deserializeShort(byte[] buffer, MutableInt offset); static void serializeShort(short val, byte[] buffer, MutableInt offset); static byte[] serializeShort(short val); static byte deserializeByte(byte[] buffer, MutableInt offset); static void serializeByte(byte val, byte[] buffer, MutableInt offset); static byte[] serializeByte(byte val); static boolean deserializeBoolean(byte[] buffer, MutableInt offset); static void serializeBoolean(boolean val, byte[] buffer, MutableInt offset); static byte[] serializeBoolean(boolean val); static char deserializeChar(byte[] buffer, MutableInt offset); static void serializeChar(char val, byte[] buffer, MutableInt offset); static byte[] serializeChar(char val); @SuppressWarnings("unchecked") static T[] createGetters(List<String> fields, Map<String, String> valueToExpression,
      Class<?> clazz, Class<?> getterClazz, Class<?> getterMethodClazz); static Getter<Object, String>[] createGettersString(List<String> fields, Map<String, String> valueToExpression,
      Class<?> clazz); static Getter<Object, Object>[] createGettersObject(List<String> fields, Map<String, String> valueToExpression,
      Class<?> clazz); static GPOGetters buildGPOGetters(Map<String, String> fieldToGetter, FieldsDescriptor fieldsDescriptor,
      Class<?> clazz); static void copyPOJOToGPO(GPOMutable mutable, GPOGetters getters, Object object); static void indirectCopy(GPOMutable dest, GPOMutable src, IndexSubset indexSubset); static int hashcode(GPOMutable gpo); static int indirectHashcode(GPOMutable gpo, IndexSubset indexSubset); static boolean equals(GPOMutable dest, GPOMutable src); static boolean subsetEquals(GPOMutable dest, GPOMutable src, IndexSubset indexSubset); static boolean indirectEquals(GPOMutable dest, GPOMutable src, IndexSubset indexSubset); static void zeroFillNumeric(GPOMutable value); static IndexSubset computeSubIndices(FieldsDescriptor child, FieldsDescriptor parent); static Map<String, Object> getDestringedData(FieldsDescriptor fd, Map<String, String> stringMap); static Map<String, Object> convertToMapIntersection(GPOMutable gpo, Fields fields); static boolean insideRange(Type type, int val); static boolean numericTypeIntOrSmaller(Type type);  }
@Test public void validDeserializeTest() throws Exception { final Map<String, Type> fieldToType = Maps.newHashMap(); final String tboolean = "tboolean"; final Boolean tbooleanv = true; final String tchar = "tchar"; final Character tcharv = 'A'; final String tstring = "tstring"; final String tstringv = "hello"; final String tfloat = "tfloat"; final Float tfloatv = 1.0f; final String tdouble = "tdouble"; final Double tdoublev = 2.0; final String tbyte = "tbyte"; final Byte tbytev = 50; final String tshort = "tshort"; final Short tshortv = 1000; final String tinteger = "tinteger"; final Integer tintegerv = 100000; final String tlong = "tlong"; final Long tlongv = 10000000000L; fieldToType.put(tboolean, Type.BOOLEAN); fieldToType.put(tchar, Type.CHAR); fieldToType.put(tstring, Type.STRING); fieldToType.put(tfloat, Type.FLOAT); fieldToType.put(tdouble, Type.DOUBLE); fieldToType.put(tbyte, Type.BYTE); fieldToType.put(tshort, Type.SHORT); fieldToType.put(tinteger, Type.INTEGER); fieldToType.put(tlong, Type.LONG); JSONObject jo = new JSONObject(); jo.put(tboolean, tbooleanv); jo.put(tchar, tcharv); jo.put(tstring, tstringv); jo.put(tfloat, tfloatv); jo.put(tdouble, tdoublev); jo.put(tbyte, tbytev); jo.put(tshort, tshortv); jo.put(tinteger, tintegerv); jo.put(tlong, tlongv); String json = jo.toString(2); logger.debug("Input json: {}", json); GPOMutable gpom = GPOUtils.deserialize(new FieldsDescriptor(fieldToType), jo); Assert.assertEquals("Results must equal", tbooleanv, gpom.getField(tboolean)); Assert.assertEquals("Results must equal", tcharv, gpom.getField(tchar)); Assert.assertEquals("Results must equal", tfloatv, gpom.getField(tfloat)); Assert.assertEquals("Results must equal", tdoublev, gpom.getField(tdouble)); Assert.assertEquals("Results must equal", tbytev, gpom.getField(tbyte)); Assert.assertEquals("Results must equal", tshortv, gpom.getField(tshort)); Assert.assertEquals("Results must equal", tintegerv, gpom.getField(tinteger)); Assert.assertEquals("Results must equal", tlongv, gpom.getField(tlong)); }