Removed javax.json
This commit is contained in:
parent
53fea439d0
commit
5dbfd2d3d4
13
pom.xml
13
pom.xml
|
@ -51,11 +51,6 @@
|
||||||
<version>1.14.8</version>
|
<version>1.14.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.json</groupId>
|
|
||||||
<artifactId>javax.json-api</artifactId>
|
|
||||||
<version>1.1</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,13 +63,7 @@
|
||||||
<version>4.11</version>
|
<version>4.11</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Provider JSON -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish</groupId>
|
|
||||||
<artifactId>javax.json</artifactId>
|
|
||||||
<version>1.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- read JSON -->
|
<!-- read JSON -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -1,149 +1,7 @@
|
||||||
package org.gcube.application.geoportal.common.model;
|
package org.gcube.application.geoportal.common.model;
|
||||||
|
|
||||||
import java.util.Collection;
|
public class BasicJSONObject {
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.json.JsonArray;
|
|
||||||
import javax.json.JsonNumber;
|
|
||||||
import javax.json.JsonObject;
|
|
||||||
import javax.json.JsonString;
|
|
||||||
import javax.json.JsonValue;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class BasicJSONObject implements JsonObject {
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
private JsonObject theObject;
|
|
||||||
|
|
||||||
public String toJson() {
|
|
||||||
return getTheObject().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int size() {
|
|
||||||
return getTheObject().size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEmpty() {
|
|
||||||
return getTheObject().isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean containsKey(Object key) {
|
|
||||||
return getTheObject().containsKey(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean containsValue(Object value) {
|
|
||||||
return getTheObject().containsValue(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonValue get(Object key) {
|
|
||||||
return getTheObject().get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonValue put(String key, JsonValue value) {
|
|
||||||
return getTheObject().put(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonValue remove(Object key) {
|
|
||||||
return getTheObject().remove(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void putAll(Map<? extends String, ? extends JsonValue> m) {
|
|
||||||
getTheObject().putAll(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
getTheObject().clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<String> keySet() {
|
|
||||||
return getTheObject().keySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Collection<JsonValue> values() {
|
|
||||||
return getTheObject().values();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<Entry<String, JsonValue>> entrySet() {
|
|
||||||
return getTheObject().entrySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonArray getJsonArray(String name) {
|
|
||||||
return getTheObject().getJsonArray(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonObject getJsonObject(String name) {
|
|
||||||
return getTheObject().getJsonObject(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonNumber getJsonNumber(String name) {
|
|
||||||
return getTheObject().getJsonNumber(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JsonString getJsonString(String name) {
|
|
||||||
return getTheObject().getJsonString(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getString(String name) {
|
|
||||||
return getTheObject().getString(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getString(String name, String defaultValue) {
|
|
||||||
return getTheObject().getString(name, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInt(String name) {
|
|
||||||
return getTheObject().getInt(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInt(String name, int defaultValue) {
|
|
||||||
return getTheObject().getInt(name, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getBoolean(String name) {
|
|
||||||
return getTheObject().getBoolean(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getBoolean(String name, boolean defaultValue) {
|
|
||||||
return getTheObject().getBoolean(name, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isNull(String name) {
|
|
||||||
return getTheObject().isNull(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ValueType getValueType() {
|
|
||||||
return getTheObject().getValueType();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,7 @@
|
||||||
package org.gcube.application.geoportal.common.model.profile;
|
package org.gcube.application.geoportal.common.model.profile;
|
||||||
|
|
||||||
import javax.json.JsonObject;
|
public class DefaultCompiler {
|
||||||
|
|
||||||
import org.gcube.application.geoportal.common.model.BasicJSONObject;
|
|
||||||
|
|
||||||
public class DefaultCompiler extends BasicJSONObject{
|
|
||||||
|
|
||||||
public DefaultCompiler(JsonObject theObject) {
|
|
||||||
super(theObject);
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,10 @@
|
||||||
package org.gcube.application.geoportal.common.model.profile;
|
package org.gcube.application.geoportal.common.model.profile;
|
||||||
|
|
||||||
import javax.json.JsonObject;
|
|
||||||
|
|
||||||
import org.gcube.application.geoportal.common.model.BasicJSONObject;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class Field extends BasicJSONObject{
|
public class Field {
|
||||||
|
|
||||||
public Field(JsonObject theObject) {
|
|
||||||
super(theObject);
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,7 @@
|
||||||
package org.gcube.application.geoportal.common.model.profile;
|
package org.gcube.application.geoportal.common.model.profile;
|
||||||
|
|
||||||
import javax.json.JsonObject;
|
public class FieldMapping {
|
||||||
|
|
||||||
import org.gcube.application.geoportal.common.model.BasicJSONObject;
|
|
||||||
|
|
||||||
public class FieldMapping extends BasicJSONObject {
|
|
||||||
|
|
||||||
public FieldMapping(JsonObject theObject) {
|
|
||||||
super(theObject);
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,7 @@
|
||||||
package org.gcube.application.geoportal.common.model.profile;
|
package org.gcube.application.geoportal.common.model.profile;
|
||||||
|
|
||||||
import javax.json.JsonObject;
|
public class IndexDefinition {
|
||||||
|
|
||||||
import org.gcube.application.geoportal.common.model.BasicJSONObject;
|
|
||||||
|
|
||||||
public class IndexDefinition extends BasicJSONObject {
|
|
||||||
|
|
||||||
public IndexDefinition(JsonObject theObject) {
|
|
||||||
super(theObject);
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,7 @@
|
||||||
package org.gcube.application.geoportal.common.model.profile;
|
package org.gcube.application.geoportal.common.model.profile;
|
||||||
|
|
||||||
import javax.json.JsonObject;
|
public class IsoMapper {
|
||||||
|
|
||||||
import org.gcube.application.geoportal.common.model.BasicJSONObject;
|
|
||||||
|
|
||||||
public class IsoMapper extends BasicJSONObject{
|
|
||||||
|
|
||||||
public IsoMapper(JsonObject theObject) {
|
|
||||||
super(theObject);
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private String className;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,40 +2,16 @@ package org.gcube.application.geoportal.common.model.profile;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.json.JsonObject;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
import org.gcube.application.geoportal.common.faults.JsonParseException;
|
|
||||||
import org.gcube.application.geoportal.common.model.BasicJSONObject;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class Profile extends BasicJSONObject{
|
@XmlRootElement
|
||||||
|
public class Profile{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Profile(JsonObject theObject) throws JsonParseException {
|
|
||||||
super(theObject);
|
|
||||||
name=theObject.getString("name");
|
|
||||||
id=theObject.getString("_id");
|
|
||||||
// JsonArray jsonFields=theObject.getJsonArray("fields");
|
|
||||||
// if(jsonFields==null)
|
|
||||||
// fields=null;
|
|
||||||
// else {
|
|
||||||
// fields=new ArrayList<Field>();
|
|
||||||
// for(int i= 0; i<jsonFields.size();i++)
|
|
||||||
// fields.add(new Field(jsonFields.getJsonObject(i)));
|
|
||||||
// }
|
|
||||||
fields=Serialization.asArray(theObject.getJsonArray("fields"), Field.class);
|
|
||||||
defaultCompilers=Serialization.asArray(theObject.getJsonArray("default_compilers"), DefaultCompiler.class);
|
|
||||||
validators=Serialization.asArray(theObject.getJsonArray("validators"), Validator.class);
|
|
||||||
isoMapper=new IsoMapper(theObject.getJsonObject("iso_mapper"));
|
|
||||||
centroidsMapping=Serialization.asArray(theObject.getJsonArray("centroid_mapping"), FieldMapping.class);
|
|
||||||
indexes=Serialization.asArray(theObject.getJsonArray("findexes"), IndexDefinition.class);
|
|
||||||
|
|
||||||
}
|
|
||||||
private String name;
|
private String name;
|
||||||
private String id;
|
private String id;
|
||||||
private List<Field> fields;
|
private List<Field> fields;
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
package org.gcube.application.geoportal.common.model.profile;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import javax.json.JsonArray;
|
|
||||||
import javax.json.JsonObject;
|
|
||||||
|
|
||||||
import org.gcube.application.geoportal.common.faults.JsonParseException;
|
|
||||||
import org.gcube.application.geoportal.common.model.BasicJSONObject;
|
|
||||||
|
|
||||||
public class Serialization {
|
|
||||||
|
|
||||||
|
|
||||||
public static <T extends BasicJSONObject> ArrayList<T> asArray(JsonArray array,Class<T> clazz) throws JsonParseException{
|
|
||||||
try {
|
|
||||||
ArrayList<T> toReturn=new ArrayList<T>();
|
|
||||||
if(array!=null)
|
|
||||||
for(int i=0;i<array.size();i++)
|
|
||||||
toReturn.add(clazz.getConstructor(JsonObject.class).newInstance(array.getJsonObject(i)));
|
|
||||||
return toReturn;
|
|
||||||
}catch(Exception e) {
|
|
||||||
throw new JsonParseException("Unable to create list of "+clazz,e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,14 +1,5 @@
|
||||||
package org.gcube.application.geoportal.common.model.profile;
|
package org.gcube.application.geoportal.common.model.profile;
|
||||||
|
|
||||||
import javax.json.JsonObject;
|
public class Validator {
|
||||||
|
|
||||||
import org.gcube.application.geoportal.common.model.BasicJSONObject;
|
|
||||||
|
|
||||||
public class Validator extends BasicJSONObject {
|
|
||||||
|
|
||||||
public Validator(JsonObject theObject) {
|
|
||||||
super(theObject);
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,13 @@
|
||||||
package org.gcube.application.geoportal.common.model.project;
|
package org.gcube.application.geoportal.common.model.project;
|
||||||
|
|
||||||
import javax.json.JsonObject;
|
|
||||||
|
|
||||||
import org.gcube.application.geoportal.common.model.BasicJSONObject;
|
import org.gcube.application.geoportal.common.model.BasicJSONObject;
|
||||||
|
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class Project extends BasicJSONObject{
|
public class Project {
|
||||||
|
|
||||||
|
|
||||||
public Project(JsonObject theObject) {
|
|
||||||
super(theObject);
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Project{
|
* Project{
|
||||||
_id:
|
_id:
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
package org.gcube.application.geoportal.common.model;
|
package org.gcube.application.geoportal.common.model;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.json.Json;
|
|
||||||
import javax.json.JsonObject;
|
|
||||||
|
|
||||||
import org.gcube.application.geoportal.common.faults.JsonParseException;
|
|
||||||
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
||||||
import org.gcube.application.geoportal.common.model.profile.Profile;
|
import org.gcube.application.geoportal.common.model.profile.Profile;
|
||||||
import org.gcube.application.geoportal.common.utils.Files;
|
import org.gcube.application.geoportal.common.utils.Files;
|
||||||
|
@ -28,6 +22,7 @@ public class SerializationTest {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
|
||||||
|
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false);
|
||||||
mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
|
mapper.configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false);
|
||||||
mapper.setSerializationInclusion(Include.NON_NULL);
|
mapper.setSerializationInclusion(Include.NON_NULL);
|
||||||
// mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
// mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||||
|
@ -36,13 +31,11 @@ public class SerializationTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void readProfile() throws FileNotFoundException, JsonParseException {
|
public void readProfile() throws JsonProcessingException, IOException {
|
||||||
JsonObject object=Json.createReader(new FileInputStream(Files.getFileFromResources("ProfileConcessioni.json"))).readObject();
|
|
||||||
|
|
||||||
System.out.println("object is "+object);
|
Profile concessione=mapper.readerFor(Profile.class).readValue(
|
||||||
Assert.assertNotNull(object);
|
Files.getFileFromResources("ProfileConcessioni.json"));
|
||||||
Profile concessione=new Profile(object);
|
System.out.println("Profile is "+mapper.writeValueAsString(concessione));
|
||||||
System.out.println("Profile is "+concessione.toJson());
|
|
||||||
|
|
||||||
Assert.assertTrue(concessione.getFields().size()>0);
|
Assert.assertTrue(concessione.getFields().size()>0);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{"id":13,"recordType":"CONCESSIONE","version":"1.0.0","licenzaID":"CC-BY","policy":"OPEN","nome":"Italia, forse","folderId":null,"lastUpdateTime":[2020,11,19,18,48,36,32000000],"lastUpdateUser":"NO NAME","creationTime":[2020,11,19,18,48,36,32000000],"creationUser":"NO NAME","introduzione":"This is my project","descrizioneContenuto":"It contains this and that","authors":["Some one","Some, oneelse"],"contributore":"Contrib 1","titolari":["Some one","Some, oneelse"],"responsabile":"Someone","editore":"Editore","fontiFinanziamento":["Big pharma","Pentagon"],"soggetto":["Research Excavation","Archeology"],"risorseCorrelate":[],"dataInizioProgetto":[2020,11,19,18,48,17,994000000],"dataFineProgetto":[2020,11,19,18,48,18,3000000],"titolareLicenza":"Qualcun altro","titolareCopyright":"Chiedilo in giro","paroleChiaveLibere":["Robba","Stuff"],"paroleChiaveICCD":["vattelapesca","somthing something"],"centroidLat":43.0,"centroidLong":9.0,"relazioneScavo":null,"immaginiRappresentative":[],"posizionamentoScavo":null,"pianteFineScavo":[],"genericContent":[]}
|
Reference in New Issue