2020-04-29 13:24:29 +02:00
|
|
|
|
2020-06-25 18:43:29 +02:00
|
|
|
package eu.dnetlib.doiboost.orcidnodoi.json;
|
2020-04-17 18:52:39 +02:00
|
|
|
|
2020-11-12 17:43:32 +01:00
|
|
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
2020-04-17 18:52:39 +02:00
|
|
|
import com.google.gson.JsonObject;
|
2020-04-29 13:24:29 +02:00
|
|
|
|
2020-11-12 17:43:32 +01:00
|
|
|
import eu.dnetlib.dhp.schema.orcid.AuthorData;
|
2020-04-24 15:50:40 +02:00
|
|
|
import eu.dnetlib.doiboost.orcid.model.WorkData;
|
2020-04-20 09:25:40 +02:00
|
|
|
|
2020-09-15 11:32:49 +02:00
|
|
|
/**
|
|
|
|
* This class converts an object to json and viceversa
|
|
|
|
*/
|
|
|
|
|
2020-04-17 18:52:39 +02:00
|
|
|
public class JsonWriter {
|
|
|
|
|
2020-11-12 17:43:32 +01:00
|
|
|
public static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPER = new ObjectMapper()
|
2021-05-14 10:58:12 +02:00
|
|
|
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
2020-11-12 17:43:32 +01:00
|
|
|
|
|
|
|
public static String create(AuthorData authorData) throws JsonProcessingException {
|
|
|
|
return OBJECT_MAPPER.writeValueAsString(authorData);
|
2020-04-29 13:24:29 +02:00
|
|
|
}
|
2020-04-24 15:50:40 +02:00
|
|
|
|
2021-04-01 17:07:49 +02:00
|
|
|
public static String create(Object obj) throws JsonProcessingException {
|
|
|
|
return OBJECT_MAPPER.writeValueAsString(obj);
|
|
|
|
}
|
|
|
|
|
2020-04-29 13:24:29 +02:00
|
|
|
public static String create(WorkData workData) {
|
|
|
|
JsonObject work = new JsonObject();
|
|
|
|
work.addProperty("oid", workData.getOid());
|
|
|
|
work.addProperty("doi", workData.getDoi());
|
|
|
|
return work.toString();
|
|
|
|
}
|
2020-04-17 18:52:39 +02:00
|
|
|
}
|