Jackson deserialization for ColumnGroup

This commit is contained in:
Antonin Delpeuch 2018-10-21 17:50:16 +01:00
parent 487f6bc131
commit bbf6dcd767

View File

@ -38,8 +38,7 @@ import java.io.Writer;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.json.JSONObject; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
@ -56,7 +55,14 @@ public class ColumnGroup {
transient public ColumnGroup parentGroup; transient public ColumnGroup parentGroup;
transient public List<ColumnGroup> subgroups; transient public List<ColumnGroup> subgroups;
public ColumnGroup(int startColumnIndex, int columnSpan, int keyColumnIndex) { @JsonCreator
public ColumnGroup(
@JsonProperty("startColumnIndex")
int startColumnIndex,
@JsonProperty("columnSpan")
int columnSpan,
@JsonProperty("keyColumnIndex")
int keyColumnIndex) {
this.startColumnIndex = startColumnIndex; this.startColumnIndex = startColumnIndex;
this.columnSpan = columnSpan; this.columnSpan = columnSpan;
this.keyColumnIndex = keyColumnIndex; this.keyColumnIndex = keyColumnIndex;
@ -98,14 +104,8 @@ public class ColumnGroup {
} }
} }
static public ColumnGroup load(String s) throws Exception { static public ColumnGroup load(String s) throws IOException {
JSONObject obj = ParsingUtilities.evaluateJsonStringToObject(s); return ParsingUtilities.mapper.readValue(s, ColumnGroup.class);
return new ColumnGroup(
obj.getInt("startColumnIndex"),
obj.getInt("columnSpan"),
obj.getInt("keyColumnIndex")
);
} }
protected void internalInitialize() { protected void internalInitialize() {