private void writePrimitive(EStructuralFeature feature, Object value) throws IOException { if (value instanceof String) { print(quote((String) value)); } else if (value instanceof byte[]) { print("\"" + new String(Base64.encodeBase64((byte[]) value), Charsets.UTF_8) + "\""); } else if (value instanceof Date) { print(Long.toString(((Date)value).getTime())); } else if (value instanceof Enum) { if (value.toString().equalsIgnoreCase("true") || value.toString().equalsIgnoreCase("false")) { print(value.toString().toLowerCase()); } else { print("\"" + value + "\""); } } else { print("" + value); } }
private void write(IdEObject object) throws IOException { if (object.eClass().getEAnnotation("wrapped") != null) { EStructuralFeature wrappedFeature = object.eClass().getEStructuralFeature("wrappedValue"); print("{"); print("\"_t\":\"" + object.eClass().getName() + "\","); print("\"_v\":"); writePrimitive(wrappedFeature, object.eGet(wrappedFeature)); print("}"); } else { print("" + object.getOid()); } }
private void writeEmbedded(IdEObject object) throws IOException { print("{"); print("\"_t\":\"" + object.eClass().getName() + "\","); for (EStructuralFeature eStructuralFeature : object.eClass().getEAllStructuralFeatures()) { print("\"" + eStructuralFeature.getName() + "\":"); writePrimitive(eStructuralFeature, object.eGet(eStructuralFeature)); if (object.eClass().getEAllStructuralFeatures().get(object.eClass().getEAllStructuralFeatures().size()-1) != eStructuralFeature) { print(","); } } print("}"); }
this.emfJsonSerializer.print("{"); IfcHeader ifcHeader = model.getModelMetaData().getIfcHeader(); if (ifcHeader != null) { this.emfJsonSerializer.print("\"header\":"); this.emfJsonSerializer.writeObject(ifcHeader); this.emfJsonSerializer.print("\n,"); this.emfJsonSerializer.print("\"objects\":["); mode = Mode.BODY; iterator = model.iterator(); this.emfJsonSerializer.print(","); } else { firstObject = false; this.emfJsonSerializer.print("]"); this.emfJsonSerializer.print("}"); mode = Mode.FOOTER; return true;
public void writeObject(IdEObject object) throws IOException { if (((IdEObjectImpl) object).getLoadingState() != State.LOADED) { print("{"); print("\"_i\":" + object.getOid() + ","); print("\"_t\":\"" + object.eClass().getName() + "\","); print("\"_s\":0"); print("}\n"); } else { print("{"); print("\"_i\":" + object.getOid() + ","); print("\"_t\":\"" + object.eClass().getName() + "\","); print("\"_s\":1"); for (EStructuralFeature eStructuralFeature : object.eClass().getEAllStructuralFeatures()) { if (eStructuralFeature.getEAnnotation("nolazyload") == null && (eStructuralFeature.getEAnnotation("hidden") == null || includeHidden)) { List<?> list = (List<?>) value; if (serializeEmptyLists || !list.isEmpty()) { print(","); int wrapped = 0; int referred = 0; print("\"_r" + eStructuralFeature.getName() + "\":["); } else if (wrapped != 0 && referred == 0) { print("\"_e" + eStructuralFeature.getName() + "\":["); } else if (wrapped == 0 && referred == 0) { print("\"_e" + eStructuralFeature.getName() + "\":["); print(","); } else {