@Test public void testFormDeSerialization() { String serializedForm = doSerializationTest(); FormDefinition deSerializedForm = definitionSerializer.deserialize(serializedForm); assertNotNull(deSerializedForm); assertEquals(formDefinition.getFields().size(), deSerializedForm.getFields().size()); for (FieldDefinition originalField : formDefinition.getFields()) { FieldDefinition resultField = deSerializedForm.getFieldById(originalField.getId()); assertNotNull(resultField); assertEquals(originalField.getClass(), resultField.getClass()); assertEquals(originalField.getName(), resultField.getName()); assertEquals(originalField.getLabel(), resultField.getLabel()); assertEquals(originalField.getStandaloneClassName(), resultField.getStandaloneClassName()); } }
@Override public FormDefinition deserialize(String serializedForm) { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(FormModel.class, formModelSerializer); builder.registerTypeAdapter(FieldDefinition.class, fieldSerializer); builder.registerTypeAdapter(ModelProperty.class, (JsonDeserializer<ModelProperty>) (json, typeOfT, context) -> context.deserialize(json, ModelPropertyImpl.class)); builder.registerTypeAdapter(TypeInfo.class, (JsonDeserializer<TypeInfo>) (json, typeOfT, context) -> context.deserialize(json, TypeInfoImpl.class)); builder.registerTypeAdapter(ModelMetaData.class, (JsonDeserializer<ModelMetaData>) (json, typeOfT, context) -> context.deserialize(json, ModelMetaDataImpl.class)); builder.registerTypeAdapter(MetaDataEntry.class, (JsonDeserializer<MetaDataEntry>) (json, typeOfT, context) -> { JsonObject jsonField = json.getAsJsonObject(); JsonElement jsonName = jsonField.get("name"); return context.deserialize(json, metaDataEntryManager.getMetaDataEntryClass(jsonName.getAsString())); }); Gson gson = builder.create(); return gson.fromJson(serializedForm, FormDefinition.class); }
FormDefinitionSerializerImpl implements FormDefinitionSerializer { @Override public FormDefinition deserialize(String serializedForm) { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(FormModel.class, formModelSerializer); builder.registerTypeAdapter(FieldDefinition.class, fieldSerializer); builder.registerTypeAdapter(ModelProperty.class, (JsonDeserializer<ModelProperty>) (json, typeOfT, context) -> context.deserialize(json, ModelPropertyImpl.class)); builder.registerTypeAdapter(TypeInfo.class, (JsonDeserializer<TypeInfo>) (json, typeOfT, context) -> context.deserialize(json, TypeInfoImpl.class)); builder.registerTypeAdapter(ModelMetaData.class, (JsonDeserializer<ModelMetaData>) (json, typeOfT, context) -> context.deserialize(json, ModelMetaDataImpl.class)); builder.registerTypeAdapter(MetaDataEntry.class, (JsonDeserializer<MetaDataEntry>) (json, typeOfT, context) -> { JsonObject jsonField = json.getAsJsonObject(); JsonElement jsonName = jsonField.get("name"); return context.deserialize(json, metaDataEntryManager.getMetaDataEntryClass(jsonName.getAsString())); }); Gson gson = builder.create(); return gson.fromJson(serializedForm, FormDefinition.class); } }
FormDefinitionSerializerImpl implements FormDefinitionSerializer { @Override public FormDefinition deserialize(String serializedForm) { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(FormModel.class, formModelSerializer); builder.registerTypeAdapter(FieldDefinition.class, fieldSerializer); builder.registerTypeAdapter(ModelProperty.class, (JsonDeserializer<ModelProperty>) (json, typeOfT, context) -> context.deserialize(json, ModelPropertyImpl.class)); builder.registerTypeAdapter(TypeInfo.class, (JsonDeserializer<TypeInfo>) (json, typeOfT, context) -> context.deserialize(json, TypeInfoImpl.class)); builder.registerTypeAdapter(ModelMetaData.class, (JsonDeserializer<ModelMetaData>) (json, typeOfT, context) -> context.deserialize(json, ModelMetaDataImpl.class)); builder.registerTypeAdapter(MetaDataEntry.class, (JsonDeserializer<MetaDataEntry>) (json, typeOfT, context) -> { JsonObject jsonField = json.getAsJsonObject(); JsonElement jsonName = jsonField.get("name"); return context.deserialize(json, metaDataEntryManager.getMetaDataEntryClass(jsonName.getAsString())); }); Gson gson = builder.create(); return gson.fromJson(serializedForm, FormDefinition.class); } @Inject  FormDefinitionSerializerImpl(FieldSerializer fieldSerializer,
                                        FormModelSerializer formModelSerializer,
                                        MetaDataEntryManager metaDataEntryManager); }
FormDefinitionSerializerImpl implements FormDefinitionSerializer { @Override public FormDefinition deserialize(String serializedForm) { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(FormModel.class, formModelSerializer); builder.registerTypeAdapter(FieldDefinition.class, fieldSerializer); builder.registerTypeAdapter(ModelProperty.class, (JsonDeserializer<ModelProperty>) (json, typeOfT, context) -> context.deserialize(json, ModelPropertyImpl.class)); builder.registerTypeAdapter(TypeInfo.class, (JsonDeserializer<TypeInfo>) (json, typeOfT, context) -> context.deserialize(json, TypeInfoImpl.class)); builder.registerTypeAdapter(ModelMetaData.class, (JsonDeserializer<ModelMetaData>) (json, typeOfT, context) -> context.deserialize(json, ModelMetaDataImpl.class)); builder.registerTypeAdapter(MetaDataEntry.class, (JsonDeserializer<MetaDataEntry>) (json, typeOfT, context) -> { JsonObject jsonField = json.getAsJsonObject(); JsonElement jsonName = jsonField.get("name"); return context.deserialize(json, metaDataEntryManager.getMetaDataEntryClass(jsonName.getAsString())); }); Gson gson = builder.create(); return gson.fromJson(serializedForm, FormDefinition.class); } @Inject  FormDefinitionSerializerImpl(FieldSerializer fieldSerializer,
                                        FormModelSerializer formModelSerializer,
                                        MetaDataEntryManager metaDataEntryManager); @Override String serialize(FormDefinition form); @Override FormDefinition deserialize(String serializedForm); }
FormDefinitionSerializerImpl implements FormDefinitionSerializer { @Override public FormDefinition deserialize(String serializedForm) { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(FormModel.class, formModelSerializer); builder.registerTypeAdapter(FieldDefinition.class, fieldSerializer); builder.registerTypeAdapter(ModelProperty.class, (JsonDeserializer<ModelProperty>) (json, typeOfT, context) -> context.deserialize(json, ModelPropertyImpl.class)); builder.registerTypeAdapter(TypeInfo.class, (JsonDeserializer<TypeInfo>) (json, typeOfT, context) -> context.deserialize(json, TypeInfoImpl.class)); builder.registerTypeAdapter(ModelMetaData.class, (JsonDeserializer<ModelMetaData>) (json, typeOfT, context) -> context.deserialize(json, ModelMetaDataImpl.class)); builder.registerTypeAdapter(MetaDataEntry.class, (JsonDeserializer<MetaDataEntry>) (json, typeOfT, context) -> { JsonObject jsonField = json.getAsJsonObject(); JsonElement jsonName = jsonField.get("name"); return context.deserialize(json, metaDataEntryManager.getMetaDataEntryClass(jsonName.getAsString())); }); Gson gson = builder.create(); return gson.fromJson(serializedForm, FormDefinition.class); } @Inject  FormDefinitionSerializerImpl(FieldSerializer fieldSerializer,
                                        FormModelSerializer formModelSerializer,
                                        MetaDataEntryManager metaDataEntryManager); @Override String serialize(FormDefinition form); @Override FormDefinition deserialize(String serializedForm);  }