APISonar


org.spongepowered.api.data.Queries.JSON

> org > spongepowered > api > data > Queries > JSON
org APIs spongepowered APIs api APIs data APIs Queries APIs JSON APIs

Example 1
protected Optional<Text> buildContent(DataView container) throws InvalidDataException {
        try {
            return container.get(Queries.JSON).map(json -> TextSerializers.JSON.deserialize(json.toString()));
        } catch (TextParseException e) {
            throw new InvalidDataException(e);
        }
    }
Example 2
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);
        }
    }