Changes based on editor review
- extract Person classes from test classes - shorten test name of one test - fix one warning
This commit is contained in:
parent
64dc02f18f
commit
e3999c9112
|
@ -16,11 +16,11 @@ import com.github.jsonldjava.utils.JsonUtils;
|
|||
public class JacksonDeserializationUnitTest {
|
||||
|
||||
@Test
|
||||
void givenAJsonLdObject_whenCompactIsUsedWithEmptyContext_thenItCanBeDeserializedIntoAJacksonAnnotatedJavaObject() throws IOException {
|
||||
void givenAJsonLdObject_whenCompactIsUsedWithEmptyContext_thenItCanBeDeserializedWithJackson() throws IOException {
|
||||
String inputJsonLd = "{\"@context\":{\"@vocab\":\"http://schema.org/\",\"knows\":{\"@type\":\"@id\"}},\"@type\":\"Person\",\"@id\":\"http://example.com/person/1234\",\"name\":\"Example Name\",\"knows\":\"http://example.com/person/2345\"}";
|
||||
|
||||
Object jsonObject = JsonUtils.fromString(inputJsonLd);
|
||||
Object compact = JsonLdProcessor.compact(jsonObject, new HashMap(), new JsonLdOptions());
|
||||
Object compact = JsonLdProcessor.compact(jsonObject, new HashMap<>(), new JsonLdOptions());
|
||||
String compactContent = JsonUtils.toString(compact);
|
||||
|
||||
assertEquals("{\"@id\":\"http://example.com/person/1234\",\"@type\":\"http://schema.org/Person\",\"http://schema.org/knows\":{\"@id\":\"http://example.com/person/2345\"},\"http://schema.org/name\":\"Example Name\"}", compactContent);
|
||||
|
|
|
@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.BeanDescription;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
|
@ -15,20 +14,9 @@ import com.fasterxml.jackson.databind.module.SimpleModule;
|
|||
import com.fasterxml.jackson.databind.ser.BeanSerializerModifier;
|
||||
import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase;
|
||||
|
||||
import de.escalon.hypermedia.hydra.mapping.Expose;
|
||||
import de.escalon.hypermedia.hydra.mapping.Vocab;
|
||||
import de.escalon.hypermedia.hydra.serialize.JacksonHydraSerializer;
|
||||
|
||||
public class HydraJsonldSerializationUnitTest {
|
||||
@Vocab("http://example.com/vocab/")
|
||||
@Expose("person")
|
||||
static class Person {
|
||||
@JsonProperty("@id")
|
||||
public String id;
|
||||
@Expose("fullName")
|
||||
public String name;
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenAHydraJsonldAnnotatedObject_whenJacksonHydraSerializerIsUsed_thenAJsonLdDocumentIsGenerated() throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.jsonld.serialization.hydrajsonld;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import de.escalon.hypermedia.hydra.mapping.Expose;
|
||||
import de.escalon.hypermedia.hydra.mapping.Vocab;
|
||||
|
||||
@Vocab("http://example.com/vocab/")
|
||||
@Expose("person")
|
||||
public class Person {
|
||||
@JsonProperty("@id")
|
||||
public String id;
|
||||
@Expose("fullName")
|
||||
public String name;
|
||||
}
|
|
@ -8,25 +8,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import ioinformarics.oss.jackson.module.jsonld.JsonldModule;
|
||||
import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldId;
|
||||
import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldLink;
|
||||
import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldNamespace;
|
||||
import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldProperty;
|
||||
import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldResource;
|
||||
import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldType;
|
||||
|
||||
public class JacksonJsonLdSerializationUnitTest {
|
||||
@JsonldResource
|
||||
@JsonldNamespace(name = "s", uri = "http://schema.org/")
|
||||
@JsonldType("s:Person")
|
||||
@JsonldLink(rel = "s:knows", name = "knows", href = "http://example.com/person/2345")
|
||||
static class Person {
|
||||
@JsonldId
|
||||
public String id = "http://example.com/person/1234";
|
||||
@JsonldProperty("s:name")
|
||||
public String name = "Example Name";
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenAJacksonJsonldAnnotatedObject_whenJsonldModuleIsUsed_thenAJsonLdDocumentIsGenerated() throws JsonProcessingException {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.baeldung.jsonld.serialization.jacksonjsonld;
|
||||
|
||||
import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldId;
|
||||
import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldLink;
|
||||
import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldNamespace;
|
||||
import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldProperty;
|
||||
import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldResource;
|
||||
import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldType;
|
||||
|
||||
@JsonldResource
|
||||
@JsonldNamespace(name = "s", uri = "http://schema.org/")
|
||||
@JsonldType("s:Person")
|
||||
@JsonldLink(rel = "s:knows", name = "knows", href = "http://example.com/person/2345")
|
||||
public class Person {
|
||||
@JsonldId
|
||||
public String id = "http://example.com/person/1234";
|
||||
@JsonldProperty("s:name")
|
||||
public String name = "Example Name";
|
||||
}
|
Loading…
Reference in New Issue