Class JsonUtil

java.lang.Object
jmri.server.json.operations.JsonUtil

public class JsonUtil extends Object
Utilities used by JSON services for Operations
  • Constructor Summary

    Constructors
    Constructor
    Description
    JsonUtil(com.fasterxml.jackson.databind.ObjectMapper mapper)
    Create utilities.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.fasterxml.jackson.databind.node.ObjectNode
    getCar(String name, Locale locale, int id)
    Get the JSON representation of a Car.
    com.fasterxml.jackson.databind.node.ObjectNode
    getCar(Car car, com.fasterxml.jackson.databind.node.ObjectNode data, Locale locale)
    Get a JSON representation of a Car.
    com.fasterxml.jackson.databind.node.ObjectNode
    getCar(Car car, Locale locale)
    Get a JSON representation of a Car.
    com.fasterxml.jackson.databind.node.ObjectNode
    getEngine(String name, Locale locale, int id)
    Get the JSON representation of an Engine.
    com.fasterxml.jackson.databind.node.ObjectNode
    getEngine(Engine engine, com.fasterxml.jackson.databind.node.ObjectNode data, Locale locale)
    Get the JSON representation of an Engine.
    com.fasterxml.jackson.databind.node.ObjectNode
    getEngine(Engine engine, Locale locale)
    Get the JSON representation of an Engine.
    com.fasterxml.jackson.databind.node.ObjectNode
    getLocation(String name, Locale locale, int id)
    Get the JSON representation of a Location.
    com.fasterxml.jackson.databind.node.ObjectNode
    getLocation(Location location, Locale locale)
    Get the JSON representation of a Location.
    com.fasterxml.jackson.databind.node.ObjectNode
     
    com.fasterxml.jackson.databind.node.ObjectNode
    getRSLocation(Location location, Locale locale)
    Get the JSON representation of a Location for use in rolling stock or train.
    com.fasterxml.jackson.databind.node.ObjectNode
    getRSTrack(Track track, Locale locale)
    Get a Track in JSON for use in rolling stock or train.
    com.fasterxml.jackson.databind.node.ObjectNode
    getTrack(Track track, Locale locale)
    Get a Track in JSON.
    com.fasterxml.jackson.databind.node.ObjectNode
    getTrain(String name, Locale locale, int id)
    Get the JSON representation of a Train.
    com.fasterxml.jackson.databind.node.ObjectNode
    getTrain(Train train, Locale locale)
    Get the JSON representation of a Train.
    com.fasterxml.jackson.databind.node.ArrayNode
    getTrains(Locale locale)
    Get all trains.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JsonUtil

      public JsonUtil(com.fasterxml.jackson.databind.ObjectMapper mapper)
      Create utilities.
      Parameters:
      mapper - the mapper used to create JSON nodes
  • Method Details

    • getCar

      public com.fasterxml.jackson.databind.node.ObjectNode getCar(String name, Locale locale, int id) throws JsonException
      Get the JSON representation of a Car.
      Parameters:
      name - the ID of the Car
      locale - the client's locale
      id - the message id set by the client
      Returns:
      the JSON representation of the Car
      Throws:
      JsonException - if no car by name exists
    • getEngine

      public com.fasterxml.jackson.databind.node.ObjectNode getEngine(Engine engine, Locale locale)
      Get the JSON representation of an Engine.
      Parameters:
      engine - the Engine
      locale - the client's locale
      Returns:
      the JSON representation of engine
    • getEngine

      public com.fasterxml.jackson.databind.node.ObjectNode getEngine(Engine engine, com.fasterxml.jackson.databind.node.ObjectNode data, Locale locale)
      Get the JSON representation of an Engine.
      Parameters:
      engine - the Engine
      data - the JSON data from getRollingStock(RollingStock, Locale)
      locale - the client's locale
      Returns:
      the JSON representation of engine
    • getEngine

      public com.fasterxml.jackson.databind.node.ObjectNode getEngine(String name, Locale locale, int id) throws JsonException
      Get the JSON representation of an Engine.
      Parameters:
      name - the ID of the Engine
      locale - the client's locale
      id - the message id set by the client
      Returns:
      the JSON representation of engine
      Throws:
      JsonException - if no engine exists by name
    • getCar

      public com.fasterxml.jackson.databind.node.ObjectNode getCar(@Nonnull Car car, Locale locale)
      Get a JSON representation of a Car.
      Parameters:
      car - the Car
      locale - the client's locale
      Returns:
      the JSON representation of car
    • getCar

      public com.fasterxml.jackson.databind.node.ObjectNode getCar(@Nonnull Car car, @Nonnull com.fasterxml.jackson.databind.node.ObjectNode data, Locale locale)
      Get a JSON representation of a Car.
      Parameters:
      car - the Car
      data - the JSON data from getRollingStock(RollingStock, Locale)
      locale - the client's locale
      Returns:
      the JSON representation of car
    • getLocation

      public com.fasterxml.jackson.databind.node.ObjectNode getLocation(@Nonnull Location location, Locale locale)
      Get the JSON representation of a Location.

      Note:use getRSLocation(Location, Locale) if including in rolling stock or train.

      Parameters:
      location - the location
      locale - the client's locale
      Returns:
      the JSON representation of location
    • getLocation

      public com.fasterxml.jackson.databind.node.ObjectNode getLocation(String name, Locale locale, int id) throws JsonException
      Get the JSON representation of a Location.
      Parameters:
      name - the ID of the location
      locale - the client's locale
      id - the message id set by the client
      Returns:
      the JSON representation of the location
      Throws:
      JsonException - if id does not match a known location
    • getTrack

      public com.fasterxml.jackson.databind.node.ObjectNode getTrack(Track track, Locale locale)
      Get a Track in JSON.

      Note:use getRSTrack(Track, Locale) if including in rolling stock or train.

      Parameters:
      track - the track to get
      locale - the client's locale
      Returns:
      a JSON representation of the track
    • getRSLocation

      public com.fasterxml.jackson.databind.node.ObjectNode getRSLocation(@Nonnull Location location, Locale locale)
      Get the JSON representation of a Location for use in rolling stock or train.

      Note:use getLocation(Location, Locale) if not including in rolling stock or train.

      Parameters:
      location - the location
      locale - the client's locale
      Returns:
      the JSON representation of location
    • getRSTrack

      public com.fasterxml.jackson.databind.node.ObjectNode getRSTrack(Track track, Locale locale)
      Get a Track in JSON for use in rolling stock or train.

      Note:use getTrack(Track, Locale) if not including in rolling stock or train.

      Parameters:
      track - the track to get
      locale - the client's locale
      Returns:
      a JSON representation of the track
    • getRollingStock

      public com.fasterxml.jackson.databind.node.ObjectNode getRollingStock(@Nonnull RollingStock rs, Locale locale)
    • getTrain

      public com.fasterxml.jackson.databind.node.ObjectNode getTrain(Train train, Locale locale)
      Get the JSON representation of a Train.
      Parameters:
      train - the train
      locale - the client's locale
      Returns:
      the JSON representation of train
    • getTrain

      public com.fasterxml.jackson.databind.node.ObjectNode getTrain(String name, Locale locale, int id) throws JsonException
      Get the JSON representation of a Train.
      Parameters:
      name - the id of the train
      locale - the client's locale
      id - the message id set by the client
      Returns:
      the JSON representation of the train with id
      Throws:
      JsonException - if id does not represent a known train
    • getTrains

      public com.fasterxml.jackson.databind.node.ArrayNode getTrains(Locale locale)
      Get all trains.
      Parameters:
      locale - the client's locale
      Returns:
      an array of all trains