Class ContractXmlCodec

java.lang.Object
mekhq.campaign.mission.contract.io.ContractXmlCodec

public final class ContractXmlCodec extends Object
XML serialization and deserialization for AbstractContract and its data records.

AbstractContract is intentionally a pure data class with no logic, so the (de)serialization lives here rather than on the type itself. Writing uses MekHQ's standard PrintWriter / MHQXMLUtility tag helpers. Reading uses a map-lookup: each element under a <contract> node is dispatched by its tag name to a handler in READERS, mirroring the pattern used by CampaignOptionsUnmarshaller / CampaignOptionCodecs.

The concrete subclass (ChaosContract, ChaosActOfPiracy, ChaosGameWorlds) is recorded as the type attribute of the <contract> element and reinstated by reflection on load, exactly as Scenario and Person do. Transient fields (the cached jump path and cached difficulty) are not persisted.

Since:
0.51.01
  • Field Details

  • Method Details

    • writeContract

      public static void writeContract(PrintWriter printWriter, int indent, AbstractContract contract, Campaign campaign)
      Writes a single contract as a <contract> element.
      Parameters:
      printWriter - the writer to emit to
      indent - the indentation level of the <contract> element
      contract - the contract to serialize
      campaign - the owning campaign (required to serialize nested Person negotiators)
    • readContract

      @Nullable public static AbstractContract readContract(Node node, Campaign campaign, megamek.Version version)
      Reconstructs a single contract from a <contract> element.
      Parameters:
      node - the <contract> element
      campaign - the owning campaign
      version - the save file's version
      Returns:
      the reconstructed contract, or null if its concrete type could not be instantiated