forked from D-Net/dnet-hadoop
example measures in serialization test
This commit is contained in:
parent
11938dac5e
commit
c54d7ca18c
|
@ -1,13 +1,14 @@
|
||||||
package eu.dnetlib.dhp.schema.oaf;
|
package eu.dnetlib.dhp.schema.oaf;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
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.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MeasureTest {
|
public class MeasureTest {
|
||||||
|
|
||||||
|
@ -17,16 +18,22 @@ public class MeasureTest {
|
||||||
@Test
|
@Test
|
||||||
public void testMeasureSerialization() throws IOException {
|
public void testMeasureSerialization() throws IOException {
|
||||||
|
|
||||||
Measure m = new Measure();
|
Measure popularity = new Measure();
|
||||||
|
popularity.setId("popularity");
|
||||||
m.setId("popularity");
|
popularity.setUnit(Lists.newArrayList(
|
||||||
m.setUnit(Lists.newArrayList(
|
|
||||||
unit("score", "0.5")));
|
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);
|
String s = OBJECT_MAPPER.writeValueAsString(m);
|
||||||
System.out.println(s);
|
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);
|
Assertions.assertNotNull(mm);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue