@Override public void setValue(Object value) { Preconditions.checkNotNull(value); if (!holder.getOptions().acceptsType(value.getClass())) { throw new IllegalArgumentException("Configuration does not accept objects of type " + value .getClass()); } this.value = value; }
@Override public void setValue(@Nullable Object value) { Preconditions.checkNotNull(value); if (!holder.getOptions().acceptsType(value.getClass())) { throw new IllegalArgumentException("Configuration does not accept objects of type " + value.getClass()); } this.value = value; }
@Override public void setValue(@Nullable Object value) { Preconditions.checkNotNull(value); if (!holder.getOptions().acceptsType(value.getClass())) { throw new IllegalArgumentException("Configuration does not accept objects of type " + value.getClass()); } this.value = value; }
/** * Set this node's value to the given value. * If the provided value is a {@link java.util.Collection} or a {@link java.util.Map}, it will be unwrapped into * the appropriate configuration node structure. * This method will also perform serialization using the appropriate TypeSerializer for the given type, or casting if no type serializer is found. * * @param type The type to use for serialization type information * @param value The value to set * @param <T> The type to serialize to * @return this */ default <T> ConfigurationNode setValue(TypeToken<T> type, T value) throws ObjectMappingException { if (value == null) { setValue(null); return this; } TypeSerializer serial = getOptions().getSerializers().get(type); if (serial != null) { serial.serialize(type, value, this); } else if (getOptions().acceptsType(value.getClass())) { setValue(value); // Just write if no applicable serializer exists? } else { throw new ObjectMappingException("No serializer available for type " + type); } return this; }
/** * Set this node's value to the given value. * * <p>If the provided value is a {@link Collection} or a {@link Map}, it will be unwrapped into * the appropriate configuration node structure.</p> * * <p>This method will also perform serialization using the appropriate TypeSerializer for the * given type, or casting if no type serializer is found.</p> * * @param type The type to use for serialization type information * @param value The value to set * @param <T> The type to serialize to * @return this */ @NonNull default <T> ConfigurationNode setValue(@NonNull TypeToken<T> type, @Nullable T value) throws ObjectMappingException { if (value == null) { setValue(null); return this; } TypeSerializer<T> serial = getOptions().getSerializers().get(type); if (serial != null) { serial.serialize(type, value, this); } else if (getOptions().acceptsType(value.getClass())) { setValue(value); // Just write if no applicable serializer exists? } else { throw new ObjectMappingException("No serializer available for type " + type); } return this; }
/** * Set this node's value to the given value. * * <p>If the provided value is a {@link Collection} or a {@link Map}, it will be unwrapped into * the appropriate configuration node structure.</p> * * <p>This method will also perform serialization using the appropriate TypeSerializer for the * given type, or casting if no type serializer is found.</p> * * @param type The type to use for serialization type information * @param value The value to set * @param <T> The type to serialize to * @return this */ @NonNull default <T> ConfigurationNode setValue(@NonNull TypeToken<T> type, @Nullable T value) throws ObjectMappingException { if (value == null) { setValue(null); return this; } TypeSerializer<T> serial = getOptions().getSerializers().get(type); if (serial != null) { serial.serialize(type, value, this); } else if (getOptions().acceptsType(value.getClass())) { setValue(value); // Just write if no applicable serializer exists? } else { throw new ObjectMappingException("No serializer available for type " + type); } return this; }