mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-18 14:58:47 +00:00
Fix for Issue 43 - Support for JSON unmarshalling of @XmlRootElement
beans.
This commit is contained in:
1 parent
6f579ba890
commit
44d95dc06c
5 files changed
+74
-16
No files matched your search
@@ -71,6 +71,7 @@ import com.avaje.ebeaninternal.server.type.TypeManager;
|
||||
import com.avaje.ebeaninternal.util.SortByClause;
|
||||
import com.avaje.ebeaninternal.util.SortByClause.Property;
|
||||
import com.avaje.ebeaninternal.util.SortByClauseParser;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -1318,10 +1319,8 @@ public class BeanDescriptor<T> {
|
||||
public EntityBean createEntityBean() {
|
||||
try {
|
||||
// Note factoryType is used indirectly via beanReflect
|
||||
EntityBean eb = (EntityBean) beanReflect.createEntityBean();
|
||||
|
||||
return eb;
|
||||
|
||||
return (EntityBean) beanReflect.createEntityBean();
|
||||
|
||||
} catch (Exception ex) {
|
||||
throw new PersistenceException(ex);
|
||||
}
|
||||
@@ -2308,6 +2307,9 @@ public class BeanDescriptor<T> {
|
||||
for (int j = 0; j < propertiesNonTransient.length; j++) {
|
||||
propertiesNonTransient[j].jsonWrite(ctx, bean);
|
||||
}
|
||||
for (int j = 0; j < propertiesTransient.length; j++) {
|
||||
propertiesTransient[j].jsonWrite(ctx, bean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2372,9 +2374,20 @@ public class BeanDescriptor<T> {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private T createJsonBean() {
|
||||
if (EntityType.XMLELEMENT.equals(entityType)) {
|
||||
try {
|
||||
return beanType.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return (T)createEntityBean();
|
||||
}
|
||||
|
||||
private ReadBeanState jsonReadObject(ReadJsonContext ctx, String path) {
|
||||
|
||||
T bean = (T) createEntityBean();
|
||||
T bean = createJsonBean();
|
||||
ctx.pushBean(bean, path, this);
|
||||
|
||||
do {
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.deploy;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -752,7 +753,11 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
|
||||
Object value = getValueIntercept(bean);
|
||||
if (value != null){
|
||||
ctx.pushParentBeanMany(bean);
|
||||
help.jsonWrite(ctx, name, value, include != null);
|
||||
if (help != null){
|
||||
help.jsonWrite(ctx, name, value, include != null);
|
||||
} else {
|
||||
ctx.toJson(name, (Collection<?>)value);
|
||||
}
|
||||
ctx.popParentBeanMany();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -259,10 +259,14 @@ public class DeployCreateProperties {
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private DeployBeanProperty createManyType(DeployBeanDescriptor<?> desc, Class<?> targetType, ManyType manyType) {
|
||||
|
||||
try {
|
||||
ScalarType<?> scalarType = typeManager.getScalarType(targetType);
|
||||
if (scalarType != null) {
|
||||
return new DeployBeanPropertySimpleCollection(desc, targetType, scalarType, manyType);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
logger.debug("expected non-scalar type"+e.getMessage());
|
||||
}
|
||||
//TODO: Handle Collection of CompoundType and Embedded Type
|
||||
return new DeployBeanPropertyAssocMany(desc, targetType, manyType);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user