use of org.spongepowered.configurate.serialize.TypeSerializerCollection in project Configurate by SpongePowered.
the class DfuSerializersTest method testCodecSerializer.
@Test
void testCodecSerializer() throws SerializationException {
final TypeSerializerCollection serializers = TypeSerializerCollection.defaults().childBuilder().register(VEC3I_TYPE, DfuSerializers.serializer(VEC3I_CODEC)).build();
final ConfigurationNode testElement = BasicConfigurationNode.root(ConfigurationOptions.defaults().serializers(serializers), n -> {
n.appendListNode().raw(4);
n.appendListNode().raw(5);
n.appendListNode().raw(8);
});
final Vector3i pos = testElement.get(VEC3I_TYPE);
assertEquals(new Vector3i(4, 5, 8), pos);
}
use of org.spongepowered.configurate.serialize.TypeSerializerCollection in project Nucleus by NucleusPowered.
the class ConfigurateHelper method setupCore.
private static TypeSerializerCollection setupCore(final INucleusServiceCollection serviceCollection, final ObjectMapper.Factory factory, final ConfigurationOptions options) {
final TypeSerializerCollection.Builder typeSerializerCollection = options.serializers().childBuilder();
// Custom type serialisers for Nucleus
typeSerializerCollection.registerAnnotatedObjects(factory);
typeSerializerCollection.register(TypeToken.get(Vector3d.class), new Vector3dTypeSerialiser());
typeSerializerCollection.register(TypeToken.get(Pattern.class), new PatternTypeSerialiser());
typeSerializerCollection.register(TypeToken.get(NucleusTextTemplate.class), new NucleusTextTemplateTypeSerialiser(serviceCollection.textTemplateFactory()));
typeSerializerCollection.register(TypeToken.get(Instant.class), new InstantTypeSerialiser());
typeSerializerCollection.register(TypeTokens.ABSTRACT_DATA_OBJECT_TYPE_TOKEN, DataObjectTranslator.INSTANCE);
typeSerializerCollection.register(TypeTokens.NAMED_LOCATION, new NamedLocationSerialiser());
typeSerializerCollection.register(TypeTokens.LOCALE, new LocaleSerialiser());
return typeSerializerCollection.build();
}
use of org.spongepowered.configurate.serialize.TypeSerializerCollection in project Configurate by SpongePowered.
the class DfuSerializersTest method testSerializerCodec.
@Test
void testSerializerCodec() throws IOException {
final TypeSerializerCollection serializers = TypeSerializerCollection.defaults().childBuilder().register(VEC3I_TYPE, DfuSerializers.serializer(VEC3I_CODEC)).build();
@Nullable final Codec<TestSerializable> codec = DfuSerializers.codec(TypeToken.get(TestSerializable.class), serializers);
assertNotNull(codec);
final DataResult<JsonElement> out = codec.encode(new TestSerializable(), JsonOps.INSTANCE, JsonOps.INSTANCE.empty());
out.error().ifPresent(err -> {
throw new RuntimeException(err.message());
});
final StringWriter buffer = new StringWriter();
try (JsonWriter writer = new JsonWriter(buffer)) {
writer.setIndent(" ");
Streams.write(out.result().orElseThrow(() -> new RuntimeException("No result present!")), writer);
}
assertLinesMatch(Resources.readLines(this.getClass().getResource("test-serialize-codec.json"), StandardCharsets.UTF_8), Arrays.asList(buffer.toString().split("\n")));
}
use of org.spongepowered.configurate.serialize.TypeSerializerCollection in project Configurate by SpongePowered.
the class DfuSerializersTest method testCodecSerializer.
@Test
void testCodecSerializer() throws SerializationException {
final TypeSerializerCollection serializers = TypeSerializerCollection.defaults().childBuilder().register(VEC3I_TYPE, DfuSerializers.serializer(VEC3I_CODEC)).build();
final ConfigurationNode testElement = BasicConfigurationNode.root(ConfigurationOptions.defaults().serializers(serializers), n -> {
n.appendListNode().raw(4);
n.appendListNode().raw(5);
n.appendListNode().raw(8);
});
@Nullable final Vector3i pos = testElement.get(VEC3I_TYPE);
assertEquals(new Vector3i(4, 5, 8), pos);
}
use of org.spongepowered.configurate.serialize.TypeSerializerCollection in project Configurate by SpongePowered.
the class DfuSerializersTest method testSerializerCodec.
@Test
void testSerializerCodec() throws IOException {
final TypeSerializerCollection serializers = TypeSerializerCollection.defaults().childBuilder().register(VEC3I_TYPE, DfuSerializers.serializer(VEC3I_CODEC)).build();
@Nullable final Codec<TestSerializable> codec = DfuSerializers.codec(TypeToken.get(TestSerializable.class), serializers);
assertNotNull(codec);
final DataResult<JsonElement> out = codec.encode(new TestSerializable(), JsonOps.INSTANCE, JsonOps.INSTANCE.empty());
out.error().ifPresent(err -> {
throw new RuntimeException(err.message());
});
final StringWriter buffer = new StringWriter();
try (JsonWriter writer = new JsonWriter(buffer)) {
writer.setIndent(" ");
Streams.write(out.result().orElseThrow(() -> new RuntimeException("No result present!")), writer);
}
assertLinesMatch(Resources.readLines(this.getClass().getResource("test-serialize-codec.json"), StandardCharsets.UTF_8), Arrays.asList(buffer.toString().split("\n")));
}
Aggregations