mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-05 04:38:10 +08:00
PL-8012 REST serialization incorrectly handles attribute of type Date if it is defined by @Temporal
This commit is contained in:
parent
598e514762
commit
8747d211bf
@ -298,12 +298,8 @@ public class EntitySerialization implements EntitySerializationAPI {
|
|||||||
} else if (fieldValue instanceof Boolean) {
|
} else if (fieldValue instanceof Boolean) {
|
||||||
jsonObject.addProperty(propertyName, (Boolean) fieldValue);
|
jsonObject.addProperty(propertyName, (Boolean) fieldValue);
|
||||||
} else {
|
} else {
|
||||||
Datatype datatype = Datatypes.get(property.getJavaType());
|
Datatype datatype = property.getRange().asDatatype();
|
||||||
if (datatype != null) {
|
|
||||||
jsonObject.addProperty(propertyName, datatype.format(fieldValue));
|
jsonObject.addProperty(propertyName, datatype.format(fieldValue));
|
||||||
} else {
|
|
||||||
jsonObject.addProperty(propertyName, String.valueOf(fieldValue));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,7 +426,7 @@ public class EntitySerialization implements EntitySerializationAPI {
|
|||||||
Class<?> propertyType = metaProperty.getJavaType();
|
Class<?> propertyType = metaProperty.getJavaType();
|
||||||
Range propertyRange = metaProperty.getRange();
|
Range propertyRange = metaProperty.getRange();
|
||||||
if (propertyRange.isDatatype()) {
|
if (propertyRange.isDatatype()) {
|
||||||
Object value = readSimpleProperty(propertyValue, propertyType);
|
Object value = readSimpleProperty(propertyValue, propertyRange.asDatatype());
|
||||||
entity.setValue(propertyName, value);
|
entity.setValue(propertyName, value);
|
||||||
} else if (propertyRange.isEnum()) {
|
} else if (propertyRange.isEnum()) {
|
||||||
String stringValue = propertyValue.getAsString();
|
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();
|
String value = valueElement.getAsString();
|
||||||
Object parsedValue = null;
|
|
||||||
try {
|
try {
|
||||||
Datatype<?> datatype = Datatypes.get(propertyType);
|
return propertyType.parse(value);
|
||||||
if (datatype != null) {
|
|
||||||
parsedValue = datatype.parse(value);
|
|
||||||
}
|
|
||||||
return parsedValue;
|
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
throw new EntitySerializationException(String.format("An error occurred while parsing property. Class [%s]. Value [%s].", propertyType, value), e);
|
throw new EntitySerializationException(String.format("An error occurred while parsing property. Class [%s]. Value [%s].", propertyType, value), e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user