FIX: Json deserialize references

This commit is contained in:
Jonas Pöhler
2021-11-12 14:46:39 +01:00
parent 0dc2550bdb
commit e7cffe99d6
3 changed files with 15 additions and 7 deletions
@@ -3038,6 +3038,10 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
return ebi.isReference() || referenceIdPropertyOnly(ebi);
}
boolean hasIdPropertyOnly(EntityBeanIntercept ebi) {
return propertiesBaseScalar.length > 0 && ebi.hasIdOnly(idPropertyIndex);
}
public boolean referenceIdPropertyOnly(EntityBeanIntercept ebi) {
return idOnlyReference && ebi.hasIdOnly(idPropertyIndex);
}
@@ -3055,6 +3059,12 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
return versionPropertyIndex > -1 && ebi.isLoadedProperty(versionPropertyIndex);
}
void setReferenceIfIdOnly(EntityBeanIntercept ebi) {
if (hasIdPropertyOnly(ebi)) {
ebi.setReference(idPropertyIndex);
}
}
/**
* Set the version value returning it in primitive long form.
*/
@@ -152,6 +152,9 @@ final class BeanDescriptorJsonHelp<T> {
}
if (contextBean == null) {
readJson.beanVisitor(bean, unmappedProperties);
if (!isNullOrZero(id)) {
desc.setReferenceIfIdOnly(bean._ebean_getIntercept());
}
}
if (path != null) {
readJson.popPath();
@@ -47,15 +47,10 @@ public class TestTextJsonReferenceBean extends BaseTestCase {
prodDesc.isReference(eb._ebean_getIntercept());
BeanState beanState = DB.beanState(refProd);
assertTrue(beanState.isNew());
assertTrue(beanState.isReference());
String name = refProd.getName();
assertNull(name);
// Set to be 'loaded' to invoke lazy loading
beanState.setLoaded();
String name2 = refProd.getName();
assertNotNull(name2);
assertNotNull(name);
}
List<Order> orders = DB.find(Order.class)