Class WfJsonMessage

java.lang.Object
org.whiteflagprotocol.java.util.WfJsonMessage

public class WfJsonMessage extends Object
Whiteflag JSON message representation class

This class represents a Whiteflag message represented in the JavaScript Object Notation (JSON) format, in accordance with Annex B of the Whiteflag specification. The basic JSON structure is as follows: { "MetaHeader" : {...}, "MessageHeader": {...}, "MessageBody": {...} }

Since:
1.0
Whiteflag standard x-reference:
Annex B. JSON Schema of Whiteflag Messages
  • Constructor Details

    • WfJsonMessage

      public WfJsonMessage(Map<String,String> metadata, Map<String,String> header, Map<String,String> body)
      Creates a new JSON representation of a Whiteflag message
      Parameters:
      metadata - the key-to-value mapping of metadata
      header - the fieldname-to-value mapping of the message header
      body - the fieldname-to-value mapping of message body
  • Method Details

    • create

      public static WfJsonMessage create(String jsonStr) throws WfUtilException
      Creates a new JSON representation of a Whiteflag message from a serialized JSON string
      Parameters:
      jsonStr - a JSON representation of a Whiteflag message
      Returns:
      a JSON message
      Throws:
      WfUtilException - if JSON is invalid
    • getMetadata

      public Map<String,String> getMetadata()
      Gets the message metadata
      Returns:
      the key-to-value mapping of the message metadata
    • getHeader

      public Map<String,String> getHeader()
      Gets the message header
      Returns:
      the fieldname-to-value mapping of the message header
    • getBody

      public Map<String,String> getBody()
      Gets the message body
      Returns:
      the fieldname-to-value mapping of the message body
    • toJson

      public String toJson() throws WfUtilException
      Creates a serialized JSON representation of a Whiteflag message
      Returns:
      the serialized JSON representation of the message
      Throws:
      WfUtilException - if no valid JSON serialization can be created