@ConfigSerializable public static final class Arg implements TextRepresentable { @Setting final boolean optional; @Setting @Nullable final Text defaultValue; final String name; // defined by node name final TextFormat format; // defined in "content" node
@Override public void serialize(TypeToken<?> type, Text obj, ConfigurationNode value) throws ObjectMappingException { String json = (String) obj.toContainer().get(Queries.JSON).get(); GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder() .setSource(() -> new BufferedReader(new StringReader(json))) .build(); try { value.setValue(gsonLoader.load()); } catch (IOException e) { throw new ObjectMappingException(e); } }
/** * Create a new object mapper that can work with objects of the given class * * @param clazz The type of object * @param <T> The type * @return An appropriate object mapper instance. May be shared with other users. * @throws ObjectMappingException If invalid annotated fields are presented */ @SuppressWarnings("unchecked") public static <T> ObjectMapper<T> forClass(Class<T> clazz) throws ObjectMappingException { return DefaultObjectMapperFactory.getInstance().getMapper(clazz); }
/** * Returns a view on this mapper that is bound to a newly created object instance * * @see #bind(Object) * @return Bound mapper attached to a new object instance * @throws ObjectMappingException If the object could not be constructed correctly */ public BoundInstance bindToNew() throws ObjectMappingException { return new BoundInstance(constructObject()); }
@Override public ObjectMapper<?> load(Class<?> key) throws Exception { return new ObjectMapper<>(key); } });
/** * Return a view on this mapper that is bound to a single object instance * * @param instance The instance to bind to * @return A view referencing this mapper and the bound instance */ public BoundInstance bind(T instance) { return new BoundInstance(instance); }
@Override public ObjectMapper<?> load(Class<?> key) throws Exception { return new GuiceObjectMapper<>(injector, key); } });
public TextConfig getText() { return textMapper.getInstance(); }
@Override public Text deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { StringWriter writer = new StringWriter(); GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder() .setIndent(0) .setSink(() -> new BufferedWriter(writer)) .setHeaderMode(HeaderMode.NONE) .build(); try { gsonLoader.save(value); } catch (IOException e) { throw new ObjectMappingException(e); } return Sponge.getDataManager().deserialize(Text.class, DataContainer.createNew().set(Queries.JSON, writer.toString())).get(); }
/** * Create a new object mapper that can work with objects of the given class using the * {@link DefaultObjectMapperFactory}. * * @param clazz The type of object * @param <T> The type * @return An appropriate object mapper instance. May be shared with other users. * @throws ObjectMappingException If invalid annotated fields are presented */ @SuppressWarnings("unchecked") public static <T> ObjectMapper<T> forClass(@NonNull Class<T> clazz) throws ObjectMappingException { return DefaultObjectMapperFactory.getInstance().getMapper(clazz); }
/** * Returns a view on this mapper that is bound to a newly created object instance * * @see #bind(Object) * @return Bound mapper attached to a new object instance * @throws ObjectMappingException If the object could not be constructed correctly */ public BoundInstance bindToNew() throws ObjectMappingException { return new BoundInstance(constructObject()); }
@Override public ObjectMapper<?> load(Class<?> key) throws Exception { return new ObjectMapper<>(key); } });
/** * Return a view on this mapper that is bound to a single object instance * * @param instance The instance to bind to * @return A view referencing this mapper and the bound instance */ public BoundInstance bind(T instance) { return new BoundInstance(instance); }
@Override public ObjectMapper<?> load(Class<?> key) throws Exception { return new GuiceObjectMapper<>(injector, key); } });
@Override public TextFormat deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { TextColor color = TextColors.NONE; GameRegistry registry = Sponge.getRegistry(); String colorId = value.getNode(NODE_COLOR).getString(); if (colorId != null) { color = registry.getType(TextColor.class, colorId).orElseThrow(() -> new ObjectMappingException("Color not found: " + colorId)); } TextStyle style = TextStyles.NONE; ConfigurationNode styleNode = value.getNode(NODE_STYLE); for (TextStyle.Base component : registry.getAllOf(TextStyle.Base.class)) { if (styleNode.getNode(component.getId().toLowerCase()).getBoolean()) { style = style.and(component); } } return TextFormat.NONE.color(color).style(style); }
/** * Create a new object mapper that can work with objects of the given class using the * {@link DefaultObjectMapperFactory}. * * @param clazz The type of object * @param <T> The type * @return An appropriate object mapper instance. May be shared with other users. * @throws ObjectMappingException If invalid annotated fields are presented */ @SuppressWarnings("unchecked") public static <T> ObjectMapper<T> forClass(@NonNull Class<T> clazz) throws ObjectMappingException { return DefaultObjectMapperFactory.getInstance().getMapper(clazz); }
/** * Returns a view on this mapper that is bound to a newly created object instance * * @see #bind(Object) * @return Bound mapper attached to a new object instance * @throws ObjectMappingException If the object could not be constructed correctly */ public BoundInstance bindToNew() throws ObjectMappingException { return new BoundInstance(constructObject()); }
@Override public ObjectMapper<?> load(Class<?> key) throws Exception { return new ObjectMapper<>(key); } });
/** * Return a view on this mapper that is bound to a single object instance * * @param instance The instance to bind to * @return A view referencing this mapper and the bound instance */ public BoundInstance bind(T instance) { return new BoundInstance(instance); }
@Override public ObjectMapper<?> load(Class<?> key) throws Exception { return new GuiceObjectMapper<>(injector, key); } });