Package megamek.common.jacksonAdapters
Class MMUReader
java.lang.Object
megamek.common.jacksonAdapters.MMUReader
This class has methods for reading objects such as SBF Formations, Units and AlphaStrikeElements from an MMU file
which uses YAML formatting.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddisallowCombinedFields(String objectType, com.fasterxml.jackson.databind.JsonNode node, String... fields) Tests the given node if it has any combination of at least two of the given fields.read(com.fasterxml.jackson.databind.JsonNode node) Read a list of objects from a Jackson JsonNode.Read a list of objects from a Jackson JsonNode.Read a list of objects from a given MMU file (YAML format, seeMMUWriter).static voidrequireFields(String objectType, com.fasterxml.jackson.databind.JsonNode node, String... fields) Tests the given node (which should be an object node that holds a full AS element or SBF Unit) if it has all the given fields.
-
Constructor Details
-
MMUReader
public MMUReader() -
MMUReader
-
-
Method Details
-
read
Read a list of objects from a given MMU file (YAML format, seeMMUWriter). The list can be empty or contain one or multiple results. If reading any part of the file fails, an exception is thrown.- Parameters:
file- The MMU file to read- Returns:
- A list of objects (AlphaStrikeElements, SBFUnits...) contained in the MMU file
- Throws:
IOException- When a read error occurs
-
read
Read a list of objects from a Jackson JsonNode. Internally used to parse nested objects.- Parameters:
node- The node to parse- Returns:
- A list of objects (AlphaStrikeElements, SBFUnits...) contained in the node
- Throws:
IOException- When a read error occurs
-
read
public List<Object> read(com.fasterxml.jackson.databind.JsonNode node, Class<?> objectType) throws IOException Read a list of objects from a Jackson JsonNode. Internally used to parse nested objects.- Parameters:
node- The node to parse- Returns:
- A list of objects (AlphaStrikeElements, SBFUnits...) contained in the node
- Throws:
IOException- When a read error occurs
-
requireFields
public static void requireFields(String objectType, com.fasterxml.jackson.databind.JsonNode node, String... fields) Tests the given node (which should be an object node that holds a full AS element or SBF Unit) if it has all the given fields. If any of the given fields is missing, an IllegalArgumentException is thrown. The given objectType can be any String, it is only used as part of the error message when a field is not found.- Parameters:
objectType- The object type such as "ASElement". Only used as part of the exception messagenode- the node containing an object to be deserializedfields- The required field names, e.g. "chassis" or "size"
-
disallowCombinedFields
public static void disallowCombinedFields(String objectType, com.fasterxml.jackson.databind.JsonNode node, String... fields) Tests the given node if it has any combination of at least two of the given fields. If that is the case, an IllegalArgumentException is thrown. The given objectType can be any String, it is only used as part of the error message. If none of the fields or only a single one of the fields is found, this method does nothing.- Parameters:
objectType- The object type such as "ASElement". Only used as part of the exception messagenode- the node containing an object to be deserializedfields- The field names, e.g. "chassis" or "size"
-