Removed javax.json

This commit is contained in:
Fabio Sinibaldi 2020-11-25 12:53:30 +01:00
parent 53fea439d0
commit 5dbfd2d3d4
13 changed files with 23 additions and 285 deletions

15
pom.xml
View File

@ -51,12 +51,7 @@
<version>1.14.8</version>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1</version>
</dependency>
@ -68,13 +63,7 @@
<version>4.11</version>
</dependency>
<!-- Provider JSON -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
<!-- read JSON -->
<dependency>

View File

@ -1,149 +1,7 @@
package org.gcube.application.geoportal.common.model;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
public class BasicJSONObject {
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();
}
}

View File

@ -1,14 +1,7 @@
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
}
}

View File

@ -1,18 +1,10 @@
package org.gcube.application.geoportal.common.model.profile;
import javax.json.JsonObject;
import org.gcube.application.geoportal.common.model.BasicJSONObject;
import lombok.Getter;
@Getter
public class Field extends BasicJSONObject{
public class Field {
public Field(JsonObject theObject) {
super(theObject);
// TODO Auto-generated constructor stub
}

View File

@ -1,14 +1,7 @@
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
}
}

View File

@ -1,15 +1,7 @@
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
}
}

View File

@ -1,15 +1,7 @@
package org.gcube.application.geoportal.common.model.profile;
import javax.json.JsonObject;
import org.gcube.application.geoportal.common.model.BasicJSONObject;
public class IsoMapper extends BasicJSONObject{
public IsoMapper(JsonObject theObject) {
super(theObject);
// TODO Auto-generated constructor stub
}
public class IsoMapper {
private String className;
}

View File

@ -2,40 +2,16 @@ package org.gcube.application.geoportal.common.model.profile;
import java.util.List;
import javax.json.JsonObject;
import org.gcube.application.geoportal.common.faults.JsonParseException;
import org.gcube.application.geoportal.common.model.BasicJSONObject;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
@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 id;
private List<Field> fields;

View File

@ -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);
}
}
}

View File

@ -1,14 +1,5 @@
package org.gcube.application.geoportal.common.model.profile;
import javax.json.JsonObject;
import org.gcube.application.geoportal.common.model.BasicJSONObject;
public class Validator extends BasicJSONObject {
public Validator(JsonObject theObject) {
super(theObject);
// TODO Auto-generated constructor stub
}
public class Validator {
}

View File

@ -1,18 +1,13 @@
package org.gcube.application.geoportal.common.model.project;
import javax.json.JsonObject;
import org.gcube.application.geoportal.common.model.BasicJSONObject;
import lombok.NoArgsConstructor;
@NoArgsConstructor
public class Project extends BasicJSONObject{
public class Project {
public Project(JsonObject theObject) {
super(theObject);
// TODO Auto-generated constructor stub
}
/**
* Project{
_id:

View File

@ -1,13 +1,7 @@
package org.gcube.application.geoportal.common.model;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
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.profile.Profile;
import org.gcube.application.geoportal.common.utils.Files;
@ -28,6 +22,7 @@ public class SerializationTest {
static {
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.setSerializationInclusion(Include.NON_NULL);
// mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
@ -36,13 +31,11 @@ public class SerializationTest {
@Test
public void readProfile() throws FileNotFoundException, JsonParseException {
JsonObject object=Json.createReader(new FileInputStream(Files.getFileFromResources("ProfileConcessioni.json"))).readObject();
public void readProfile() throws JsonProcessingException, IOException {
System.out.println("object is "+object);
Assert.assertNotNull(object);
Profile concessione=new Profile(object);
System.out.println("Profile is "+concessione.toJson());
Profile concessione=mapper.readerFor(Profile.class).readValue(
Files.getFileFromResources("ProfileConcessioni.json"));
System.out.println("Profile is "+mapper.writeValueAsString(concessione));
Assert.assertTrue(concessione.getFields().size()>0);

View File

@ -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":[]}