Class JsonConnection

java.lang.Object
jmri.jmris.JmriConnection
jmri.server.json.JsonConnection

public class JsonConnection extends JmriConnection
Abstraction of DataOutputStream and WebSocket.Connection classes for JSON clients.
  • Field Details

  • Constructor Details

  • Method Details

    • getObjectMapper

      @Nonnull public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
      Get the ObjectMapper for this connection.
      Returns:
      the ObjectMapper
    • sendMessage

      public void sendMessage(@Nonnull com.fasterxml.jackson.databind.JsonNode message, @Nonnull JsonRequest request) throws IOException
      Send a JsonNode to the instantiated connection.

      This method throws an IOException so the server or servlet holding the connection open can respond to the exception.

      If JsonServerPreferences.getValidateServerMessages() is true, a message is sent to the client that validation failed instead of the intended message.

      Overriding methods must ensure that message is only sent if validated.

      Parameters:
      message - the object or array to send as a message
      request - the JSON request
      Throws:
      IOException - if unable to send the message
    • sendMessage

      public void sendMessage(@Nonnull com.fasterxml.jackson.databind.JsonNode message, int id) throws IOException
      Send a JsonNode to the instantiated connection.

      This method throws an IOException so the server or servlet holding the connection open can respond to the exception.

      If JsonServerPreferences.getValidateServerMessages() is true, a message is sent to the client that validation failed instead of the intended message.

      Overriding methods must ensure that message is only sent if validated.

      Parameters:
      message - the object or array to send as a message
      id - the message id set by the client
      Throws:
      IOException - if unable to send the message
    • getVersion

      public String getVersion()
    • setVersion

      public void setVersion(String version)