protected <Y> void parseInlineJson(X targetEntity, ErraiAttribute<? super X, Y> attr, JSONValue attrJsonValue, ErraiEntityManager eem) { Class<Y> attributeType = attr.getJavaType(); Y value; // FIXME this should search all managed types, or maybe all embeddables. not just entities. if (eem.getMetamodel().getEntities().contains(attributeType)) { ErraiIdentifiableType<Y> attrEntityType = eem.getMetamodel().entity(attributeType); value = attrEntityType.fromJson(eem, attrJsonValue); } else { value = JsonUtil.basicValueFromJson(attrJsonValue, attributeType); } attr.set(targetEntity, value); }
/** * Returns an inline JSON representation of the value of the given attribute * of the given entity instance. * * @param targetEntity * The instance of the entity to retrieve the attribute value from. * Not null. * @param attr * The attribute to read from {@code targetEntity}. Not null. * @param eem * The ErraiEntityManager that owns the entity. Not null. * @return a JSONValue that represents the requested attribute value of the * given entity. Never null, although it could be JSONNull. */ private <Y> JSONValue makeInlineJson(X targetEntity, ErraiAttribute<? super X, Y> attr, ErraiEntityManager eem) { Class<Y> attributeType = attr.getJavaType(); Y attrValue = attr.get(Assert.notNull(targetEntity)); // FIXME this should search all managed types, or maybe all embeddables. not just entities. // TODO it would be better to code-generate an Attribute.asJson() method than to do this at runtime if (eem.getMetamodel().getEntities().contains(attributeType)) { ErraiIdentifiableType<Y> attrEntityType = eem.getMetamodel().entity(attributeType); return attrEntityType.toJson(eem, attrValue); } return JsonUtil.basicValueToJson(attrValue); }