change EDCE parser for support new format
This commit is contained in:
@@ -12,6 +12,7 @@ public class EDCEParser {
|
||||
public static EDPacket parseJSON(String json) throws IOException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
|
||||
return mapper.readValue(json, EDPacket.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,13 @@ package ru.trader.edce.entities;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
public class Ship {
|
||||
private String name;
|
||||
private Fuel fuel;
|
||||
private Cargo cargo;
|
||||
private Map<String, Slot> modules = new LinkedHashMap<>();
|
||||
private Map<String, List<Slot>> modules = new LinkedHashMap<>();
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@@ -36,11 +34,11 @@ public class Ship {
|
||||
this.cargo = cargo;
|
||||
}
|
||||
|
||||
public Map<String, Slot> getModules() {
|
||||
public Map<String, List<Slot>> getModules() {
|
||||
return modules;
|
||||
}
|
||||
|
||||
public void setModules(Map<String, Slot> modules) {
|
||||
public void setModules(Map<String, List<Slot>> modules) {
|
||||
this.modules = modules;
|
||||
}
|
||||
|
||||
@@ -67,7 +65,7 @@ public class Ship {
|
||||
@JsonIgnore
|
||||
public Module getFSD(){
|
||||
if (modules == null) return null;
|
||||
Slot fsd = modules.get("FrameShiftDrive");
|
||||
Slot fsd = modules.get("FrameShiftDrive").get(0);
|
||||
return fsd != null ? fsd.getModule() : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -167,4 +167,23 @@ public class ParseTest extends Assert {
|
||||
assertEquals(128064117L, fsd.getId());
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user