/** * Creates a {@link DataBinder} for the provided model instance. * * @param model * The instance of a {@link Bindable} type, must not be null. */ public static <T> DataBinder<T> forModel(final T model) { return new DataBinder<>(model); }
/** * Creates a {@link DataBinder} for a list with models of the provided type. * * @param modelType * The bindable type, must not be null. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> DataBinder<List<T>> forListOfType(final Class<T> modelType) { return new DataBinder<List<T>>((Class) List.class); }
/** * Creates a {@link DataBinder} for a new model instance of the provided type. * * @param modelType * The bindable type, must not be null. */ public static <T> DataBinder<T> forType(final Class<T> modelType) { return new DataBinder<>(modelType); }
/** * Creates a {@link DataBinder} for a list with models of the provided type. * * @param modelType * The bindable type, must not be null. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> DataBinder<List<T>> forListOfType(final Class<T> modelType) { return new DataBinder<List<T>>((Class) List.class); }
/** * Creates a {@link DataBinder} for the provided model instance. * * @param model * The instance of a {@link Bindable} type, must not be null. */ public static <T> DataBinder<T> forModel(final T model) { return new DataBinder<>(model); }
/** * Creates a {@link DataBinder} for the provided model instance. * * @param model * The instance of a {@link Bindable} type, must not be null. */ public static <T> DataBinder<T> forModel(final T model) { return new DataBinder<>(model); }
/** * Creates a {@link DataBinder} for a new model instance of the provided type. * * @param modelType * The bindable type, must not be null. */ public static <T> DataBinder<T> forType(final Class<T> modelType) { return new DataBinder<>(modelType); }
/** * Creates a {@link DataBinder} for a list with models of the provided type. * * @param modelType * The bindable type, must not be null. */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static <T> DataBinder<List<T>> forListOfType(final Class<T> modelType) { return new DataBinder<List<T>>((Class) List.class); }
/** * Creates a {@link DataBinder} for a new model instance of the provided type. * * @param modelType * The bindable type, must not be null. */ public static <T> DataBinder<T> forType(final Class<T> modelType) { return new DataBinder<>(modelType); }
/** * Creates a {@link DataBinder} for a map. * * @param propertyTypes * A collection of name-type pairs describing the properties that can be in map models for the returned * binder. Adding other properties to the model of the returned binder will cause * {@link NonExistingPropertyException NonExistingPropertyExceptions} to be thrown. */ public static DataBinder<Map<String, Object>> forMap( final Map<String, PropertyType> propertyTypes ) { final DataBinder<Map<String, Object>> binder = new DataBinder<>(); binder.proxy = new MapBindableProxy(propertyTypes); return binder; }
/** * Creates a {@link DataBinder} for a map. * * @param propertyTypes * A collection of name-type pairs describing the properties that can be in map models for the returned * binder. Adding other properties to the model of the returned binder will cause * {@link NonExistingPropertyException NonExistingPropertyExceptions} to be thrown. */ public static DataBinder<Map<String, Object>> forMap( final Map<String, PropertyType> propertyTypes ) { final DataBinder<Map<String, Object>> binder = new DataBinder<>(); binder.proxy = new MapBindableProxy(propertyTypes); return binder; }
/** * Creates a {@link DataBinder} for a map. * * @param propertyTypes * A collection of name-type pairs describing the properties that can be in map models for the returned * binder. Adding other properties to the model of the returned binder will cause * {@link NonExistingPropertyException NonExistingPropertyExceptions} to be thrown. */ public static DataBinder<Map<String, Object>> forMap( final Map<String, PropertyType> propertyTypes ) { final DataBinder<Map<String, Object>> binder = new DataBinder<>(); binder.proxy = new MapBindableProxy(propertyTypes); return binder; }
private void bindJSONToObject(Object obj, String json) throws IOException, JsonProcessingException { MutablePropertyValues mpv = new MutablePropertyValues(); JsonNode rootNode = new ObjectMapper().readTree(json); for (Iterator<Entry<String, JsonNode>> iter = rootNode.getFields(); iter.hasNext(); ) { Entry<String, JsonNode> entry = iter.next(); String name = entry.getKey(); JsonNode node = entry.getValue(); if (node.isArray()) { List<String> values = new ArrayList<String>(); for (JsonNode elem : node) { values.add(elem.getTextValue()); } mpv.addPropertyValue(name, values); if (logger.isDebugEnabled()) { logger.debug(name + "=" + ArrayUtils.toString(values)); } } else { mpv.addPropertyValue(name, node.getTextValue()); if (logger.isDebugEnabled()) { logger.debug(name + "=" + node.getTextValue()); } } } DataBinder dataBinder = new DataBinder(obj); dataBinder.bind(mpv); }