@Override public TextTemplate deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { this.root = value; this.openArg = value.getNode(NODE_OPEN_ARG).getString(TextTemplate.DEFAULT_OPEN_ARG); this.closeArg = value.getNode(NODE_CLOSE_ARG).getString(TextTemplate.DEFAULT_CLOSE_ARG); Text content = value.getNode(NODE_CONTENT).getValue(TypeToken.of(Text.class)); List<Object> elements = new ArrayList<>(); parse(content, elements); return TextTemplate.of(elements.toArray(new Object[elements.size()])); }
@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); }
/** * Gets the value typed using the appropriate type conversion from {@link Types} * * @see #getValue() * @return The appropriate type conversion, null if no appropriate value is available */ default String getString() { return getString(null); }
@Override public Pattern deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { try { return Pattern.compile(value.getString()); } catch (PatternSyntaxException ex) { throw new ObjectMappingException(ex); } }
/** * Gets the value typed using the appropriate type conversion from {@link Types} * * @see #getValue() * @return The appropriate type conversion, null if no appropriate value is available */ @Nullable default String getString() { return getString(null); }
@Override public UUID deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { try { return UUID.fromString(value.getString()); } catch (IllegalArgumentException ex) { throw new ObjectMappingException("Value not a UUID", ex); } }
@Override public BlockState deserialize(TypeToken<?> type, ConfigurationNode value) { return BlockUtil.getBlockStateFromString(value.getString()); }
@Override public SpongeBlockFilter deserialize(TypeToken<?> type, ConfigurationNode value) { return new SpongeBlockFilter(value.getString()); }
@Override public TextTemplate deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { this.root = value; this.openArg = value.getNode(NODE_OPEN_ARG).getString(TextTemplate.DEFAULT_OPEN_ARG); this.closeArg = value.getNode(NODE_CLOSE_ARG).getString(TextTemplate.DEFAULT_CLOSE_ARG); Text content = value.getNode(NODE_CONTENT).getValue(TypeToken.of(Text.class)); List<Object> elements = new ArrayList<>(); parse(content, elements); return TextTemplate.of(elements.toArray(new Object[elements.size()])); }
@Override public UUID deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException { try { return UUID.fromString(value.getString()); } catch (IllegalArgumentException ex) { throw new ObjectMappingException("Value not a UUID", ex); } }
@Override public Pattern deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException { try { return Pattern.compile(value.getString()); } catch (PatternSyntaxException ex) { throw new ObjectMappingException(ex); } }
@Override public UUID deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException { try { return UUID.fromString(value.getString()); } catch (IllegalArgumentException ex) { throw new ObjectMappingException("Value not a UUID", ex); } }
@Override public Pattern deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException { try { return Pattern.compile(value.getString()); } catch (PatternSyntaxException ex) { throw new ObjectMappingException(ex); } }
@Override public DataStore deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { String dataStoreType = value.getNode("type").getString(value.getKey().toString()); Optional<DataStoreFactory> factory = DataStoreFactories.get(dataStoreType); if (!factory.isPresent()) { throw new ObjectMappingException("Unknown DataStore type " + dataStoreType); } try { return factory.get().createDataStore(value.getKey().toString(), value); } catch (PermissionsLoadingException e) { throw new ObjectMappingException(e); } }
@Override public UserPermissionStruct deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { String username = value.getKey().toString(); String password = value.getNode("password").getString(); TreeNode perms = SecurityService.permissionTreeFromConfig(value.getNode("permissions")); return new UserPermissionStruct(username, password, perms); }
@Override public Object deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { Class<?> clazz = getInstantiableType(type, value.getNode("__class__").getString()); return value.getOptions().getObjectMapperFactory().getMapper(clazz).bindToNew().populate(value); }
@Override public Object deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException { Class<?> clazz = getInstantiableType(type, value.getNode("__class__").getString()); return value.getOptions().getObjectMapperFactory().getMapper(clazz).bindToNew().populate(value); }
@Override public Object deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException { Class<?> clazz = getInstantiableType(type, value.getNode("__class__").getString()); return value.getOptions().getObjectMapperFactory().getMapper(clazz).bindToNew().populate(value); }
private void appendGlobalConfiguration() { appendHeader("Global Configuration"); LogListBlock log = new LogListBlock(); LogListBlock configLog = log.putChild("Configuration"); for (ConfigValue config : CraftBookPlugin.spongeInst().getConfig().getConfigurationNodes()) { ConfigurationNode node = SimpleCommentedConfigurationNode.root(); config.serializeDefault(node); configLog.put(config.getKey(), node.getString("UNKNOWN")); } append(log); appendln(); }
@Test public void testStringSerializer() throws ObjectMappingException { final TypeToken<String> stringType = TypeToken.of(String.class); final TypeSerializer<String> stringSerializer = SERIALIZERS.get(stringType); final ConfigurationNode node = SimpleConfigurationNode.root().setValue("foobar"); assertEquals("foobar", stringSerializer.deserialize(stringType, node)); stringSerializer.serialize(stringType, "foobarbaz", node); assertEquals("foobarbaz", node.getString()); }