From c54d7ca18c1c4a4f8fe64b05d94d3e74fb25b4a0 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Mon, 4 May 2020 17:02:40 +0200 Subject: [PATCH] example measures in serialization test --- .../dnetlib/dhp/schema/oaf/MeasureTest.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/dhp-schemas/src/test/java/eu/dnetlib/dhp/schema/oaf/MeasureTest.java b/dhp-schemas/src/test/java/eu/dnetlib/dhp/schema/oaf/MeasureTest.java index 25d929db2..4275e2c56 100644 --- a/dhp-schemas/src/test/java/eu/dnetlib/dhp/schema/oaf/MeasureTest.java +++ b/dhp-schemas/src/test/java/eu/dnetlib/dhp/schema/oaf/MeasureTest.java @@ -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 m = Lists.newArrayList(popularity, influence); + String s = OBJECT_MAPPER.writeValueAsString(m); System.out.println(s); - Measure mm = OBJECT_MAPPER.readValue(s, Measure.class); + List mm = OBJECT_MAPPER.readValue(s, new TypeReference>() { }); Assertions.assertNotNull(mm); }