本文整理汇总了Java中ninja.leaping.configurate.objectmapping.serialize.TypeSerializer.deserialize方法的典型用法代码示例。如果您正苦于以下问题:Java TypeSerializer.deserialize方法的具体用法?Java TypeSerializer.deserialize怎么用?Java TypeSerializer.deserialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ninja.leaping.configurate.objectmapping.serialize.TypeSerializer
的用法示例。
在下文中一共展示了TypeSerializer.deserialize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserializeFrom
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; //导入方法依赖的package包/类
public void deserializeFrom(Object instance, ConfigurationNode node) throws ObjectMappingException {
TypeSerializer<?> serial = node.getOptions().getSerializers().get(this.fieldType);
if (serial == null) {
throw new ObjectMappingException("No TypeSerializer found for field " + field.getName() + " of type "
+ this.fieldType);
}
Object newVal = node.isVirtual() ? null : serial.deserialize(this.fieldType, node);
try {
if (newVal == null) {
Object existingVal = field.get(instance);
if (existingVal != null) {
serializeTo(instance, node);
}
} else {
field.set(instance, newVal);
}
} catch (IllegalAccessException e) {
throw new ObjectMappingException("Unable to deserialize field " + field.getName(), e);
}
}
示例2: getValue
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T> T getValue(TypeToken<T> type, T def) throws ObjectMappingException {
Object value = getValue();
if (value == null) {
if (def != null && getOptions().shouldCopyDefaults()) {
setValue(type, def);
}
return def;
}
TypeSerializer serial = getOptions().getSerializers().get(type);
if (serial == null) {
if (type.getRawType().isInstance(value)) {
return (T) type.getRawType().cast(value);
} else {
if (def != null && getOptions().shouldCopyDefaults()) {
setValue(type, def);
}
return def;
}
}
return (T) serial.deserialize(type, this);
}
示例3: testEnumValueSerializer
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; //导入方法依赖的package包/类
@Test
public void testEnumValueSerializer() throws ObjectMappingException {
final TypeToken<TestEnum> enumType = TypeToken.of(TestEnum.class);
final TypeSerializer<TestEnum> enumSerializer = SERIALIZERS.get(enumType);
SimpleConfigurationNode node = SimpleConfigurationNode.root();
node.getNode("present_val").setValue("first");
node.getNode("another_present_val").setValue("SECOND");
node.getNode(("casematters_val")).setValue("tHiRd");
node.getNode(("casematters_val_lowercase")).setValue("third");
node.getNode("invalid_val").setValue("3rd");
assertEquals(TestEnum.FIRST, enumSerializer.deserialize(enumType, node.getNode("present_val")));
assertEquals(TestEnum.SECOND, enumSerializer.deserialize(enumType, node.getNode("another_present_val")));
assertEquals(TestEnum.Third, enumSerializer.deserialize(enumType, node.getNode("casematters_val")));
assertEquals(TestEnum.third, enumSerializer.deserialize(enumType, node.getNode("casematters_val_lowercase")));
expectedException.expect(ObjectMappingException.class);
enumSerializer.deserialize(enumType, node.getNode("invalid_val"));
}
示例4: testInvalidMapValueTypes
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; //导入方法依赖的package包/类
@Test
public void testInvalidMapValueTypes() throws ObjectMappingException {
final TypeToken<Map<TestEnum, Integer>> mapTestEnumIntType = new TypeToken<Map<TestEnum, Integer>>() {};
final TypeSerializer<Map<TestEnum, Integer>> mapTestEnumIntSerializer =
SERIALIZERS.get(mapTestEnumIntType);
final ConfigurationNode value = SimpleConfigurationNode.root();
value.getNode("FIRST").setValue(5);
value.getNode("SECOND").setValue(8);
Map<TestEnum, Integer> des = mapTestEnumIntSerializer.deserialize(mapTestEnumIntType, value);
final ConfigurationNode serialVal = SimpleConfigurationNode.root();
mapTestEnumIntSerializer.serialize(mapTestEnumIntType, des, serialVal);
assertEquals(value.getValue(), serialVal.getValue());
//assertEquals(value, serialVal);
}
示例5: testMapSerializerRemovesDeletedKeys
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; //导入方法依赖的package包/类
@Test
public void testMapSerializerRemovesDeletedKeys() throws ObjectMappingException {
final TypeToken<Map<String, Integer>> mapStringIntType = new TypeToken<Map<String, Integer>>() {};
final TypeSerializer<Map<String, Integer>> mapStringIntSerializer = SERIALIZERS.get(mapStringIntType);
final ConfigurationNode value = SimpleConfigurationNode.root();
value.getNode("fish").setValue(5);
value.getNode("bugs").setValue("124880");
value.getNode("time").setValue("-1");
@SuppressWarnings("unchecked")
final Map<String, Integer> deserialized = mapStringIntSerializer.deserialize(mapStringIntType, value);
deserialized.remove("fish");
mapStringIntSerializer.serialize(mapStringIntType, deserialized, value);
assertTrue(value.getNode("fish").isVirtual());
assertFalse(value.getNode("bugs").isVirtual());
}
示例6: deserialize
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; //导入方法依赖的package包/类
@Override
public Multimap deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException {
final Multimap<Object, Object> multimap = LinkedHashMultimap.create();
if (node.hasMapChildren()) {
TypeToken<?> key = type.resolveType(Multimap.class.getTypeParameters()[0]);
TypeToken<?> value = type.resolveType(Multimap.class.getTypeParameters()[1]);
TypeSerializer keySerial = node.getOptions().getSerializers().get(key);
TypeSerializer valueSerial = node.getOptions().getSerializers().get(value);
if (keySerial == null) {
throw new ObjectMappingException("No type serializer available for type " + key);
}
if (valueSerial == null) {
throw new ObjectMappingException("No type serializer available for type " + value);
}
for (Map.Entry<Object, ? extends ConfigurationNode> ent : node.getChildrenMap().entrySet()) {
Object keyValue = keySerial.deserialize(key, SimpleConfigurationNode.root().setValue(ent.getKey()));
Object valueValue = valueSerial.deserialize(value, ent.getValue());
if (keyValue == null || valueValue == null) {
continue;
}
multimap.put(keyValue, valueValue);
}
}
return multimap;
}
示例7: testListRawTypes
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; //导入方法依赖的package包/类
@Test
public void testListRawTypes() throws ObjectMappingException {
final TypeToken<List> rawType = TypeToken.of(List.class);
final TypeSerializer<List> serial = SERIALIZERS.get(rawType);
final ConfigurationNode value = SimpleConfigurationNode.root();
value.getAppendedNode().setValue(1);
value.getAppendedNode().setValue("dog");
value.getAppendedNode().setValue(2.4);
expectedException.expectMessage("Raw types");
serial.deserialize(rawType, value);
}
示例8: testAnnotatedObjectSerializer
import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; //导入方法依赖的package包/类
@Test
public void testAnnotatedObjectSerializer() throws ObjectMappingException {
final TypeToken<TestObject> testNodeType = TypeToken.of(TestObject.class);
final TypeSerializer<TestObject> testObjectSerializer = SERIALIZERS.get(testNodeType);
final ConfigurationNode node = SimpleConfigurationNode.root();
node.getNode("int").setValue("42");
node.getNode("name").setValue("Bob");
TestObject object = testObjectSerializer.deserialize(testNodeType, node);
assertEquals(42, object.value);
assertEquals("Bob", object.name);
}