From 8747d211bf015bdd5cca95fbb28b62aa35ba0c7c Mon Sep 17 00:00:00 2001 From: krivopustov Date: Sun, 16 Oct 2016 19:22:45 +0400 Subject: [PATCH] PL-8012 REST serialization incorrectly handles attribute of type Date if it is defined by @Temporal --- .../serialization/EntitySerialization.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/modules/global/src/com/haulmont/cuba/core/app/serialization/EntitySerialization.java b/modules/global/src/com/haulmont/cuba/core/app/serialization/EntitySerialization.java index 651b126f82..5921f3ad3a 100644 --- a/modules/global/src/com/haulmont/cuba/core/app/serialization/EntitySerialization.java +++ b/modules/global/src/com/haulmont/cuba/core/app/serialization/EntitySerialization.java @@ -298,12 +298,8 @@ public class EntitySerialization implements EntitySerializationAPI { } else if (fieldValue instanceof Boolean) { jsonObject.addProperty(propertyName, (Boolean) fieldValue); } else { - Datatype datatype = Datatypes.get(property.getJavaType()); - if (datatype != null) { - jsonObject.addProperty(propertyName, datatype.format(fieldValue)); - } else { - jsonObject.addProperty(propertyName, String.valueOf(fieldValue)); - } + Datatype datatype = property.getRange().asDatatype(); + jsonObject.addProperty(propertyName, datatype.format(fieldValue)); } } @@ -430,7 +426,7 @@ public class EntitySerialization implements EntitySerializationAPI { Class propertyType = metaProperty.getJavaType(); Range propertyRange = metaProperty.getRange(); if (propertyRange.isDatatype()) { - Object value = readSimpleProperty(propertyValue, propertyType); + Object value = readSimpleProperty(propertyValue, propertyRange.asDatatype()); entity.setValue(propertyName, value); } else if (propertyRange.isEnum()) { String stringValue = propertyValue.getAsString(); @@ -459,15 +455,10 @@ public class EntitySerialization implements EntitySerializationAPI { } - protected Object readSimpleProperty(JsonElement valueElement, Class propertyType) { + protected Object readSimpleProperty(JsonElement valueElement, Datatype propertyType) { String value = valueElement.getAsString(); - Object parsedValue = null; try { - Datatype datatype = Datatypes.get(propertyType); - if (datatype != null) { - parsedValue = datatype.parse(value); - } - return parsedValue; + return propertyType.parse(value); } catch (ParseException e) { throw new EntitySerializationException(String.format("An error occurred while parsing property. Class [%s]. Value [%s].", propertyType, value), e); }