Class JsonUtil


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

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.fasterxml.jackson.databind.node.ObjectNode getCar​(java.lang.String name, java.util.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, java.util.Locale locale)
      Get a JSON representation of a Car.
      com.fasterxml.jackson.databind.node.ObjectNode getCar​(Car car, java.util.Locale locale)
      Get a JSON representation of a Car.
      com.fasterxml.jackson.databind.node.ObjectNode getEngine​(java.lang.String name, java.util.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, java.util.Locale locale)
      Get the JSON representation of an Engine.
      com.fasterxml.jackson.databind.node.ObjectNode getEngine​(Engine engine, java.util.Locale locale)
      Get the JSON representation of an Engine.
      com.fasterxml.jackson.databind.node.ObjectNode getLocation​(java.lang.String name, java.util.Locale locale, int id)
      Get the JSON representation of a Location.
      com.fasterxml.jackson.databind.node.ObjectNode getLocation​(Location location, java.util.Locale locale)
      Get the JSON representation of a Location.
      com.fasterxml.jackson.databind.node.ObjectNode getRollingStock​(RollingStock rs, java.util.Locale locale)  
      com.fasterxml.jackson.databind.node.ObjectNode getRSLocation​(Location location, java.util.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, java.util.Locale locale)
      Get a Track in JSON for use in rolling stock or train.
      com.fasterxml.jackson.databind.node.ObjectNode getTrack​(Track track, java.util.Locale locale)
      Get a Track in JSON.
      com.fasterxml.jackson.databind.node.ObjectNode getTrain​(java.lang.String name, java.util.Locale locale, int id)
      Get the JSON representation of a Train.
      com.fasterxml.jackson.databind.node.ObjectNode getTrain​(Train train, java.util.Locale locale)
      Get the JSON representation of a Train.
      com.fasterxml.jackson.databind.node.ArrayNode getTrains​(java.util.Locale locale)
      Get all trains.
      • Methods inherited from class java.lang.Object

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

      • JsonUtil

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

      • getCar

        public com.fasterxml.jackson.databind.node.ObjectNode getCar​(java.lang.String name,
                                                                     java.util.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,
                                                                        java.util.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,
                                                                        java.util.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​(java.lang.String name,
                                                                        java.util.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,
                                                                     java.util.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,
                                                                     java.util.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,
                                                                          java.util.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​(java.lang.String name,
                                                                          java.util.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,
                                                                       java.util.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,
                                                                            java.util.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,
                                                                         java.util.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
      • getTrain

        public com.fasterxml.jackson.databind.node.ObjectNode getTrain​(Train train,
                                                                       java.util.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​(java.lang.String name,
                                                                       java.util.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​(java.util.Locale locale)
        Get all trains.
        Parameters:
        locale - the client's locale
        Returns:
        an array of all trains