Merge pull request #9830 from mdhtr/mdhtr/BAEL-1488_json-ld

BAEL-1488: JSON-LD
This commit is contained in:
Jonathan Cook 2020-08-07 10:58:11 +02:00 committed by GitHub
commit d8d5d6ae50
6 changed files with 88 additions and 20 deletions

View File

@ -42,14 +42,10 @@ public class JacksonDeserializationUnitTest {
ObjectMapper objectMapper = new ObjectMapper();
Person person = objectMapper.readValue(compactContent, Person.class);
Person expectedPerson = new Person();
expectedPerson.id = "http://example.com/person/1234";
expectedPerson.name = "Example Name";
expectedPerson.knows = new Link();
expectedPerson.knows.id = "http://example.com/person/2345";
Person expectedPerson = new Person("http://example.com/person/1234", "Example Name", new Link("http://example.com/person/2345"));
assertEquals(expectedPerson.id, person.id);
assertEquals(expectedPerson.name, person.name);
assertEquals(expectedPerson.knows.id, person.knows.id);
assertEquals(expectedPerson.getId(), person.getId());
assertEquals(expectedPerson.getName(), person.getName());
assertEquals(expectedPerson.getKnows().getId(), person.getKnows().getId());
}
}

View File

@ -6,14 +6,62 @@ import com.fasterxml.jackson.annotation.JsonProperty;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Person {
@JsonProperty("@id")
public String id;
private String id;
@JsonProperty("http://schema.org/name")
public String name;
private String name;
@JsonProperty("http://schema.org/knows")
public Link knows;
private Link knows;
public Person() {
}
public Person(String id, String name, Link knows) {
this.id = id;
this.name = name;
this.knows = knows;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Link getKnows() {
return knows;
}
public void setKnows(Link knows) {
this.knows = knows;
}
public static class Link {
@JsonProperty("@id")
public String id;
private String id;
public Link() {
}
public Link(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
}

View File

@ -23,9 +23,7 @@ public class HydraJsonldSerializationUnitTest {
objectMapper.registerModule(getJacksonHydraSerializerModule());
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
Person person = new Person();
person.id = "http://example.com/person/1234";
person.name = "Example Name";
Person person = new Person("http://example.com/person/1234", "Example Name");
String personJsonLd = objectMapper.writeValueAsString(person);

View File

@ -8,8 +8,21 @@ import de.escalon.hypermedia.hydra.mapping.Vocab;
@Vocab("http://example.com/vocab/")
@Expose("person")
public class Person {
private String id;
private String name;
public Person(String id, String name) {
this.id = id;
this.name = name;
}
@JsonProperty("@id")
public String id;
public String getId() {
return id;
}
@Expose("fullName")
public String name;
public String getName() {
return name;
}
}

View File

@ -15,7 +15,7 @@ public class JacksonJsonLdSerializationUnitTest {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JsonldModule());
Person person = new Person();
Person person = new Person("http://example.com/person/1234", "Example Name");
String personJsonLd = objectMapper.writeValueAsString(person);
assertEquals("{"

View File

@ -13,7 +13,20 @@ import ioinformarics.oss.jackson.module.jsonld.annotation.JsonldType;
@JsonldLink(rel = "s:knows", name = "knows", href = "http://example.com/person/2345")
public class Person {
@JsonldId
public String id = "http://example.com/person/1234";
private String id;
@JsonldProperty("s:name")
public String name = "Example Name";
private String name;
public Person(String id, String name) {
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
}