@Override public Map<Object, Object> loadInto(final Value<FullEntity<?>> node, final LoadContext ctx, final Path path, Map<Object, Object> into) { // Make this work more like collections than atomic values if (node == null) throw new SkipException(); if (into == null) //noinspection unchecked into = (Map<Object, Object>)fact.constructMap(mapType); else into.clear(); for (final String name : node.get().getNames()) { final Object key = stringifier.fromString(name); final Value<?> nodeValue = node.get().getValue(name); @SuppressWarnings("unchecked") final Object value = componentTranslator.load((Value)nodeValue, ctx, path.extend(name)); into.put(key, value); } return into; }
/** * Gets the relevant property from the container, detecting alsoload collisions. * * @return the value obtained from the container * @throws IllegalStateException if there are multiple alsoload name matches */ private Value<D> getPropertyFromContainer(final FullEntity<?> container, final Path containerPath) { String foundName = null; Value<D> value = null; for (String name: property.getLoadNames()) { if (container.contains(name)) { if (foundName != null) throw new IllegalStateException("Collision trying to load field; multiple name matches for '" + property.getName() + "' at '" + containerPath.extend(foundName) + "' and '" + containerPath.extend(name) + "'"); //noinspection unchecked value = container.getValue(name); foundName = name; } } if (foundName == null) throw new SkipException(); else return value; }
@SuppressWarnings("unchecked") @Override public Object toModel(Value<?> input) { if (input instanceof NullValue) { return null; } EntityValue entityValue = (EntityValue) input; FullEntity<?> entity = entityValue.get(); Map<String, Object> map; if (Modifier.isAbstract(mapClass.getModifiers())) { if (SortedMap.class.equals(mapClass)) { map = new TreeMap<>(); } else { map = new HashMap<>(); } } else { map = (Map<String, Object>) IntrospectionUtils.instantiateObject(mapClass); } for (String property : entity.getNames()) { map.put(property, valueMapper.toModel(entity.getValue(property))); } return map; }
Map<String, Object> map = new HashMap<>(); for (String property : entity.getNames()) { map.put(property, toModel(entity.getValue(property)));
if (!example.getMatcher().isIgnoredPath(persistentProperty.getName())) { String fieldName = persistentProperty.getFieldName(); Value<?> value = probeEntity.getValue(fieldName); if (value instanceof NullValue && example.getMatcher().getNullHandler() != ExampleMatcher.NullHandler.INCLUDE) {
@Override public Object toModel(Value<?> input) { if (input.getType() == ValueType.NULL) { return null; } try { FullEntity<?> entity = ((EntityValue) input).get(); ConstructorMetadata constructorMetadata = metadata.getConstructorMetadata(); Object embeddedObject = constructorMetadata.getConstructorMethodHandle().invoke(); for (PropertyMetadata propertyMetadata : metadata.getPropertyMetadataCollection()) { String mappedName = propertyMetadata.getMappedName(); if (entity.contains(mappedName)) { Value<?> propertyValue = entity.getValue(mappedName); Object fieldValue = propertyMetadata.getMapper().toModel(propertyValue); propertyMetadata.getWriteMethod().invoke(embeddedObject, fieldValue); } } if (constructorMetadata.isBuilderConstructionStrategy()) { embeddedObject = metadata.getConstructorMetadata().getBuildMethodHandle() .invoke(embeddedObject); } return embeddedObject; } catch (Throwable exp) { throw new MappingException(exp); } }