public class JsonLdSerializer
extends java.lang.Object
An example for serialization:
JsonLdSerializer serializer = new JsonLdSerializer(true);
Thing object = CoreFactory.newThingBuilder().setName(Text.of("name")).build();
String jsonldStr = serializer.serialize(object);
The serialized JSON-LD string should look like:
{
"@context": "http://schema.org",
"@type": "Thing",
"name": "name"
}
If there are more than one objects to be serialized, the overloaded methodserialize(List<? extends Thing> objects) could also be called.
Warning: serializing process will remove the outer brackets([]) in generated JSON-LD if the
objects list only contains one object.
An example for deserialization:
List<Thing> objects = serializer.deserialize(jsonldStr);
Thing thing = (Thing) (objects.get(0));
Text name = (Text)(thing.getName().get(0)); | Constructor and Description |
|---|
JsonLdSerializer(boolean setPrettyPrinting) |
JsonLdSerializer(boolean setPrettyPrinting,
boolean disableHtmlEscaping) |
| Modifier and Type | Method and Description |
|---|---|
java.util.List<Thing> |
deserialize(java.lang.String json)
Deserialized the JSON-LD string into schema.org objects.
|
java.lang.String |
serialize(java.util.List<? extends Thing> objects)
Serializes a list of schema.org objects.
|
java.lang.String |
serialize(Thing object)
Serializes one schema.org object.
|
public JsonLdSerializer(boolean setPrettyPrinting)
public JsonLdSerializer(boolean setPrettyPrinting,
boolean disableHtmlEscaping)
public java.lang.String serialize(java.util.List<? extends Thing> objects) throws JsonLdSyntaxException, com.google.gson.JsonIOException
JsonLdSyntaxException - if the objects cannot be serialized to JSON-LD.com.google.gson.JsonIOException - if there was a problem writing to the JSON writer.public java.lang.String serialize(Thing object) throws JsonLdSyntaxException, com.google.gson.JsonIOException
JsonLdSyntaxException - if the object cannot be serialized to JSON-LD.com.google.gson.JsonIOException - if there was a problem writing to the JSON writer.public java.util.List<Thing> deserialize(java.lang.String json) throws JsonLdSyntaxException, com.google.gson.JsonSyntaxException
JsonLdSyntaxException - if the JSON-LD string could not be deserialized to schema.org
types.com.google.gson.JsonSyntaxException - if the JSON-LD string has JSON syntax error.