private String getJSONString(JsonGenerator jg, PdxInstance pdxInstance) throws JsonGenerationException, IOException { jg.writeStartObject(); List<String> pdxFields = pdxInstance.getFieldNames(); for (String pf : pdxFields) { Object value = pdxInstance.getField(pf); jg.writeFieldName(pf); writeValue(jg, value, pf); } jg.writeEndObject(); return null; }
/** * Returns the keys from the given object or the indexes from an array * * @param obj an array or an object * @return the keys for an object or the indexes for an array */ public Collection<String> getPropertyKeys(Object obj) { if (isArray(obj)) { List l = (List) obj; List<String> keys = new ArrayList<String>(l.size()); for (int i = 0; i < l.size(); i++) { keys.add(String.valueOf(i)); } return keys; } else { return ((PdxInstance)obj).getFieldNames(); } } }
/** * Returns the keys from the given object or the indexes from an array * * @param obj an array or an object * @return the keys for an object or the indexes for an array */ public Collection<String> getPropertyKeys(Object obj) { if (isArray(obj)) { List l = (List) obj; List<String> keys = new ArrayList<String>(l.size()); for (int i = 0; i < l.size(); i++) { keys.add(String.valueOf(i)); } return keys; } else { return ((PdxInstance)obj).getFieldNames(); } } }
/** * Returns the keys from the given object or the indexes from an array * * @param obj an array or an object * @return the keys for an object or the indexes for an array */ public Collection<String> getPropertyKeys(Object obj) { if (isArray(obj)) { List l = (List) obj; List<String> keys = new ArrayList<String>(l.size()); for (int i = 0; i < l.size(); i++) { keys.add(String.valueOf(i)); } return keys; } else { return ((PdxInstance)obj).getFieldNames(); } } }
private PdxInstance checkPdxInstance(PdxInstance pi) throws IOException, ClassNotFoundException { // serialize the pi and make sure it can be deserialized PdxInstance pi2 = (PdxInstance) serializeAndDeserialize(pi); assertEquals(pi, pi2); assertEquals(pi.hashCode(), pi2.hashCode()); assertEquals(pi.getFieldNames(), pi2.getFieldNames()); return pi2; }
PdxInstance pdxInstance = (PdxInstance) object; w.write('{'); for (String field : pdxInstance.getFieldNames()) { Object fieldValue = pdxInstance.getField(field); writeKeyValue(w, field, fieldValue, fieldValue.getClass());
public void testGetField() throws IOException, ClassNotFoundException { PdxInstance instance = getPdx(new TestPdx() { public void toData(PdxWriter out) { out.writeBoolean("field1", false); out.writeInt("field2", 53); out.writeObject("field3", new TestPdx() { public void toData(PdxWriter writer) { writer.writeString("afield", "hello"); } }); } }); assertEquals(Arrays.asList(new String[]{"field1", "field2", "field3"}), instance.getFieldNames()); assertEquals(instance.getField("field2"), Integer.valueOf(53)); assertEquals(instance.getField("field1"), Boolean.FALSE); PdxInstance fieldInstance = (PdxInstance) instance.getField("field3"); assertEquals(Arrays.asList(new String[]{"afield"}), fieldInstance.getFieldNames()); assertEquals("hello", fieldInstance.getField("afield")); }
PdxInstance pdxInstance = (PdxInstance) object; if(write)w.write('{'); for (String field : pdxInstance.getFieldNames()) { Object fieldValue = pdxInstance.getField(field); if(write){
private static String pdxToJson(PdxInstance obj) { if(obj!=null){ try{ GfJsonObject json = new GfJsonObject(); for(String field : obj.getFieldNames()){ Object fieldValue = obj.getField(field); if(fieldValue!=null){ if(JsonUtil.isPrimitiveOrWrapper(fieldValue.getClass())){ json.put(field, fieldValue); }else{ json.put(field, fieldValue.getClass()); } } } return json.toString(); }catch(GfJsonException e){ return null; } } return null; }
private static String pdxToJson(PdxInstance obj) { if(obj!=null){ try{ GfJsonObject json = new GfJsonObject(); for(String field : obj.getFieldNames()){ Object fieldValue = obj.getField(field); if(fieldValue!=null){ if(JsonUtil.isPrimitiveOrWrapper(fieldValue.getClass())){ json.put(field, fieldValue); }else{ json.put(field, fieldValue.getClass()); } } } return json.toString(); }catch(GfJsonException e){ return null; } } return null; }
public void testGetFieldName() throws IOException, ClassNotFoundException { setupSerializer(new ExplicitFieldNameAutoSerializer(false, "com.gemstone.gemfire.pdx.DomainObjectPdxAuto"), true); DomainObject objOut = new DomainObjectPdxAuto(4); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(objOut, out); PdxInstance pi = (PdxInstance)DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); System.out.println("fieldNames=" + pi.getFieldNames()); assertEquals(false, pi.hasField("long_0")); assertEquals(true, pi.hasField("_long_0")); assertEquals(true, pi.hasField("string_0")); assertEquals(objOut, pi.getObject()); }
List<String> pdxFields = pdxInstance.getFieldNames();