@Override public String toJson(Object obj) { return JSONFormatter.toJSON((PdxInstance)obj); }
objectStarts(currentState); currentState = states.ObJECT_START; PdxInstanceHelper tmp = getPdxInstance(jp, currentState, null); currentPdxList.addObjectField(currentFieldName, tmp); currentState = states.OBJECT_ENDS; arrayStarts(currentState); PdxListHelper tmp = currentPdxList.addListField(); currentPdxList = tmp; arrayEnds(currentState); if(currentPdxList.getParent() == null) return currentPdxList; boolFound(currentState); currentState = states.SCALER_FOUND; currentPdxList.addBooleanField(jp.getBooleanValue()); nullfound(currentState); currentState = states.SCALER_FOUND; currentPdxList.addNullField(null); doublefound(currentState); currentState = states.SCALER_FOUND; setNumberField(jp,currentPdxList); break;
objectStarts(currentState); currentState = states.ObJECT_START; objectEnds(currentState); currentState = states.OBJECT_ENDS; currentPdxInstance.endObjectField("endobject"); fieldFound(currentState); arrayStarts(currentState); PdxListHelper list = getList(jp, currentState, null); currentPdxInstance.addListField(currentFieldName, list); currentState = states.LIST_FOUND; boolFound(currentState); currentState = states.SCALER_FOUND; currentPdxInstance.addBooleanField(currentFieldName, jp.getValueAsBoolean()); nullfound(currentState); currentState = states.SCALER_FOUND; currentPdxInstance.addNullField(currentFieldName); doublefound(currentState); currentState = states.SCALER_FOUND; setNumberField(jp, currentPdxInstance, currentFieldName); currentFieldName = null; break;
public void VerifyJSONString(JSONData jd) { Region r = getRootRegion("testSimplePdx"); PdxInstance pdx = JSONFormatter.fromJSON(jd.getJsonString()); r.put(1, pdx); pdx = (PdxInstance)r.get(1); String getJsonString = JSONFormatter.toJSON(pdx); String o1 = jsonParse(jd.getJsonString()); String o2 = jsonParse(getJsonString); junit.framework.Assert.assertEquals("Json Strings are not equal " + jd.getFileName() + " " + Boolean.getBoolean("pdxToJson.unqouteFieldNames"), o1, o2); PdxInstance pdx2 = JSONFormatter.fromJSON(getJsonString); junit.framework.Assert.assertEquals("Pdx are not equal; json filename " + jd.getFileName(), pdx, pdx2); }
/** * To create PdxInstance from JSON string * * @return the PdxInstance. * @throws JSONFormatterException if unable to parse JSON doucment */ public static PdxInstance fromJSON(String jsonString) { JsonParser jp = null; try { jp = new JsonFactory().createParser(jsonString); enableJSONParserFeature(jp); return new JSONFormatter().getPdxInstance(jp, states.NONE, null).getPdxInstance(); } catch (JsonParseException jpe) { throw new JSONFormatterException("Could not parse JSON document " , jpe); } catch (IOException e) { throw new JSONFormatterException("Could not parse JSON document: " + jp.getCurrentLocation(), e); } catch(Exception e) { throw new JSONFormatterException("Could not parse JSON document: " + jp.getCurrentLocation(), e); } }
@Override public void setValue(String theValue) throws StandardException { // stream = null; rawLength = -1; // cKey = null; // value = theValue; if (theValue != null) { PdxInstance jsonPdxInstance1 = null; try { jsonPdxInstance1 = JSONFormatter.fromJSON(theValue); } catch (JSONFormatterException je) { //showing only first 255 chars of the input String s = theValue; if (theValue.length() > 255) { s = theValue.substring(0, 255); } throw StandardException.newException(SQLState.LANG_INVALID_JSON, je, s, 255); } jsonPdxInstanceBytes = ((PdxInstanceImpl) jsonPdxInstance1).toBytes(); } else { jsonPdxInstanceBytes = null; } this.rawData = null; }
public void VerifyJSONByteArray(JSONData jd) { Region r = getRootRegion("testSimplePdx"); PdxInstance pdx = JSONFormatter.fromJSON(jd.getJsonByteArray()); r.put(1, pdx); pdx = (PdxInstance)r.get(1); byte[] jsonByteArray = JSONFormatter.toJSONByteArray(pdx); byte[] o1 = jsonParse(jd.getJsonByteArray()); byte[] o2 = jsonParse(jsonByteArray); // junit.framework.Assert.assertEquals("Pdx byte aray are not equal after fetching from cache " + jd.getFileName(), o1, o2); compareByteArray(o1, o2); PdxInstance pdx2 = JSONFormatter.fromJSON(jsonByteArray); boolean pdxequals = pdx.equals(pdx2); junit.framework.Assert.assertEquals("Pdx are not equal for byte array ; json filename " + jd.getFileName(), pdx, pdx2 ); } public void compareByteArray(byte[] b1, byte[] b2) {
objectStarts(currentState); currentState = states.ObJECT_START; PdxInstanceHelper tmp = getPdxInstance(jp, currentState, null); currentPdxList.addObjectField(currentFieldName, tmp); currentState = states.OBJECT_ENDS; arrayStarts(currentState); PdxListHelper tmp = currentPdxList.addListField(); currentPdxList = tmp; arrayEnds(currentState); if(currentPdxList.getParent() == null) return currentPdxList; boolFound(currentState); currentState = states.SCALER_FOUND; currentPdxList.addBooleanField(jp.getBooleanValue()); nullfound(currentState); currentState = states.SCALER_FOUND; currentPdxList.addNullField(null); doublefound(currentState); currentState = states.SCALER_FOUND; setNumberField(jp,currentPdxList); break;
objectStarts(currentState); currentState = states.ObJECT_START; objectEnds(currentState); currentState = states.OBJECT_ENDS; currentPdxInstance.endObjectField("endobject"); fieldFound(currentState); arrayStarts(currentState); PdxListHelper list = getList(jp, currentState, null); currentPdxInstance.addListField(currentFieldName, list); currentState = states.LIST_FOUND; boolFound(currentState); currentState = states.SCALER_FOUND; currentPdxInstance.addBooleanField(currentFieldName, jp.getValueAsBoolean()); nullfound(currentState); currentState = states.SCALER_FOUND; currentPdxInstance.addNullField(currentFieldName); doublefound(currentState); currentState = states.SCALER_FOUND; setNumberField(jp, currentPdxInstance, currentFieldName); currentFieldName = null; break;
/** * To create PdxInstance from JSON string * * @return the PdxInstance. * @throws JSONFormatterException if unable to parse JSON doucment */ public static PdxInstance fromJSON(byte[] jsonByteArray) { JsonParser jp = null; try { jp = new JsonFactory().createParser(jsonByteArray); enableJSONParserFeature(jp); return new JSONFormatter().getPdxInstance(jp, states.NONE, null).getPdxInstance(); } catch (JsonParseException jpe) { throw new JSONFormatterException("Could not parse JSON document " , jpe); } catch (IOException e) { throw new JSONFormatterException("Could not parse JSON document: " + jp.getCurrentLocation(), e); } catch(Exception e) { throw new JSONFormatterException("Could not parse JSON document: " + jp.getCurrentLocation(), e); } }
@Override public void setValue(String theValue) throws StandardException { // stream = null; rawLength = -1; // cKey = null; // value = theValue; if (theValue != null) { PdxInstance jsonPdxInstance1 = null; try { jsonPdxInstance1 = JSONFormatter.fromJSON(theValue); } catch (JSONFormatterException je) { //showing only first 255 chars of the input String s = theValue; if (theValue.length() > 255) { s = theValue.substring(0, 255); } throw StandardException.newException(SQLState.LANG_INVALID_JSON, je, s, 255); } jsonPdxInstanceBytes = ((PdxInstanceImpl) jsonPdxInstance1).toBytes(); } else { jsonPdxInstanceBytes = null; } this.rawData = null; }
@Override public String toJson(Object obj) { return JSONFormatter.toJSON((PdxInstance)obj); }
/** * To create PdxInstance from JSON string * * @return the PdxInstance. * @throws JSONFormatterException if unable to parse JSON doucment */ public static PdxInstance fromJSON(byte[] jsonByteArray) { JsonParser jp = null; try { jp = new JsonFactory().createJsonParser(jsonByteArray); enableJSONParserFeature(jp); return new JSONFormatter().getPdxInstance(jp, states.NONE, null).getPdxInstance(); } catch (JsonParseException jpe) { throw new JSONFormatterException("Could not parse JSON document " , jpe); } catch (IOException e) { throw new JSONFormatterException("Could not parse JSON document: " + jp.getCurrentLocation(), e); } catch(Exception e) { throw new JSONFormatterException("Could not parse JSON document: " + jp.getCurrentLocation(), e); } }
@Override public void setValue(String theValue) throws StandardException { // stream = null; rawLength = -1; // cKey = null; // value = theValue; if (theValue != null) { PdxInstance jsonPdxInstance1 = null; try { jsonPdxInstance1 = JSONFormatter.fromJSON(theValue); } catch (JSONFormatterException je) { //showing only first 255 chars of the input String s = theValue; if (theValue.length() > 255) { s = theValue.substring(0, 255); } throw StandardException.newException(SQLState.LANG_INVALID_JSON, je, s, 255); } jsonPdxInstanceBytes = ((PdxInstanceImpl) jsonPdxInstance1).toBytes(); } else { jsonPdxInstanceBytes = null; } this.rawData = null; }
@Override public String toJson(Object obj) { return JSONFormatter.toJSON((PdxInstance)obj); }
/** * To create PdxInstance from JSON string * * @return the PdxInstance. * @throws JSONFormatterException if unable to parse JSON doucment */ public static PdxInstance fromJSON(String jsonString) { JsonParser jp = null; try { jp = new JsonFactory().createJsonParser(jsonString); enableJSONParserFeature(jp); return new JSONFormatter().getPdxInstance(jp, states.NONE, null).getPdxInstance(); } catch (JsonParseException jpe) { throw new JSONFormatterException("Could not parse JSON document " , jpe); } catch (IOException e) { throw new JSONFormatterException("Could not parse JSON document: " + jp.getCurrentLocation(), e); } catch(Exception e) { throw new JSONFormatterException("Could not parse JSON document: " + jp.getCurrentLocation(), e); } }
public PdxInstance toObject(String json) { JSONObject jsonObject = null; try { jsonObject = new JSONObject(json); } catch (JSONException e) { throw new MessageTransformationException(e.getMessage()); } return JSONFormatter.fromJSON(jsonObject.toString()); }
protected String convertPdxToJson(final PdxInstance pdxObj){ return (pdxObj != null ? JSONFormatter.toJSON(pdxObj) : null); }
public String toString(Object obj) { if (obj == null) { return null; } if (obj instanceof PdxInstance) { String json = JSONFormatter.toJSON((PdxInstance) obj); // de-pretty return json.replaceAll("\\r\\n\\s*", "").replaceAll("\\n\\s*", "") .replaceAll("\\s*:\\s*", ":").trim(); } return obj.toString(); } }
private static <K, V> String toJSON(List list) { StringBuilder sb = new StringBuilder(); String delim = ""; for (Object listObject : (List)list) { sb.append(delim); if (listObject instanceof PdxInstance) { sb.append(JSONFormatter.toJSON((PdxInstance)listObject)); delim = ",\n"; } else { sb.append(listObject); delim = ","; } } return sb.toString(); } }