example measures in serialization test

This commit is contained in:
Claudio Atzori 2020-05-04 17:02:40 +02:00
parent 11938dac5e
commit c54d7ca18c
1 changed files with 13 additions and 6 deletions

View File

@ -1,13 +1,14 @@
package eu.dnetlib.dhp.schema.oaf;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.List;
public class MeasureTest {
@ -17,16 +18,22 @@ public class MeasureTest {
@Test
public void testMeasureSerialization() throws IOException {
Measure m = new Measure();
m.setId("popularity");
m.setUnit(Lists.newArrayList(
Measure popularity = new Measure();
popularity.setId("popularity");
popularity.setUnit(Lists.newArrayList(
unit("score", "0.5")));
Measure influence = new Measure();
influence.setId("influence");
influence.setUnit(Lists.newArrayList(
unit("score", "0.3")));
List<Measure> m = Lists.newArrayList(popularity, influence);
String s = OBJECT_MAPPER.writeValueAsString(m);
System.out.println(s);
Measure mm = OBJECT_MAPPER.readValue(s, Measure.class);
List<Measure> mm = OBJECT_MAPPER.readValue(s, new TypeReference<List<Measure>>() { });
Assertions.assertNotNull(mm);
}