Archived
0

change EDCE parser for support new format

This commit is contained in:
iMoHax
2015-10-08 11:59:48 +03:00
parent 83865402b3
commit 6f7bf5b308
3 changed files with 25 additions and 7 deletions

View File

@@ -12,6 +12,7 @@ public class EDCEParser {
public static EDPacket parseJSON(String json) throws IOException { public static EDPacket parseJSON(String json) throws IOException {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
return mapper.readValue(json, EDPacket.class); return mapper.readValue(json, EDPacket.class);
} }

View File

@@ -2,15 +2,13 @@ package ru.trader.edce.entities;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.LinkedHashMap; import java.util.*;
import java.util.Map;
import java.util.Objects;
public class Ship { public class Ship {
private String name; private String name;
private Fuel fuel; private Fuel fuel;
private Cargo cargo; private Cargo cargo;
private Map<String, Slot> modules = new LinkedHashMap<>(); private Map<String, List<Slot>> modules = new LinkedHashMap<>();
public String getName() { public String getName() {
return name; return name;
@@ -36,11 +34,11 @@ public class Ship {
this.cargo = cargo; this.cargo = cargo;
} }
public Map<String, Slot> getModules() { public Map<String, List<Slot>> getModules() {
return modules; return modules;
} }
public void setModules(Map<String, Slot> modules) { public void setModules(Map<String, List<Slot>> modules) {
this.modules = modules; this.modules = modules;
} }
@@ -67,7 +65,7 @@ public class Ship {
@JsonIgnore @JsonIgnore
public Module getFSD(){ public Module getFSD(){
if (modules == null) return null; if (modules == null) return null;
Slot fsd = modules.get("FrameShiftDrive"); Slot fsd = modules.get("FrameShiftDrive").get(0);
return fsd != null ? fsd.getModule() : null; return fsd != null ? fsd.getModule() : null;
} }

View File

@@ -167,4 +167,23 @@ public class ParseTest extends Assert {
assertEquals(128064117L, fsd.getId()); assertEquals(128064117L, fsd.getId());
assertEquals("Int_Hyperdrive_Size4_Class5", fsd.getName()); assertEquals("Int_Hyperdrive_Size4_Class5", fsd.getName());
} }
@Test
public void testParse8() throws Exception {
LOG.info("Test parse json8");
InputStream is = getClass().getResourceAsStream("/edce/edce8.json");
String json = read(is);
LOG.trace("Parse json:");
LOG.trace("{}", json);
EDPacket packet = EDCEParser.parseJSON(json);
Commander commander = packet.getCommander();
assertNotNull(commander);
System system = packet.getLastSystem();
assertNotNull(system);
Starport starport = packet.getLastStarport();
assertNotNull(starport);
Ship ship = packet.getShip();
assertNotNull(ship);
}
} }