use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project LanternServer by LanternPowered.
the class TextTypeSerializer method deserialize.
@Override
public Text deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
final StringWriter writer = new StringWriter();
final 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 TextSerializers.JSON.deserialize(writer.toString());
}
use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project AtherysCore by Atherys-Horizons.
the class AbstractConfigurateAdapter method deserialize.
/*@Override
public void write( JsonWriter out, T value ) throws IOException {
GsonConfigurationLoader loader = GsonConfigurationLoader.builder().setLenient( true ).setIndent( 0 ).build();
try {
ConfigurationNode node = loader.createEmptyNode().setValue( TypeToken.of( clazz ), value );
StringWriter writer = new StringWriter();
loader.saveInternal( node, writer );
String json = writer.toString();
AtherysCore.getInstance().getLogger().info( "Write: " + json ); // DEBUG
out.jsonValue( json );
} catch ( ObjectMappingException e ) {
e.printStackTrace();
}
}
@Override
public T read( JsonReader in ) throws IOException {
String json = parser.parse( in ).toString();
AtherysCore.getInstance().getLogger().info( "Read: " + json ); // DEBUG
GsonConfigurationLoader loader = GsonConfigurationLoader.builder().setSource( () -> new BufferedReader( new StringReader( json ) ) ).build();
ConfigurationNode node = loader.load();
try {
return node.getValue( TypeToken.of( clazz ) );
} catch ( ObjectMappingException e ) {
e.printStackTrace();
}
return null;
}*/
@Override
public T deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String jsonString = json.toString();
try {
GsonConfigurationLoader loader = GsonConfigurationLoader.builder().setSource(() -> new BufferedReader(new StringReader(jsonString))).build();
ConfigurationNode node = loader.load();
try {
return node.getValue(TypeToken.of(clazz));
} catch (ObjectMappingException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project AtherysCore by Atherys-Horizons.
the class PluginConfig method save.
/**
* Save the contents of the object mapper to the config file. This will override config values already-present in the file.
*/
public void save() {
try {
SimpleConfigurationNode out = SimpleConfigurationNode.root();
this.configMapper.serialize(out);
this.loader.save(out);
} catch (ObjectMappingException | IOException e) {
e.printStackTrace();
}
}
use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project SpongeAPI by SpongePowered.
the class TextFormatConfigSerializer method deserialize.
@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);
}
use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project SpongeAPI by SpongePowered.
the class TextConfigSerializer method serialize.
@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);
}
}
Aggregations