Package jmri.server.json.operations
Class JsonUtil
- java.lang.Object
-
- jmri.server.json.operations.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.ObjectNodegetCar(java.lang.String name, java.util.Locale locale, int id)Get the JSON representation of a Car.com.fasterxml.jackson.databind.node.ObjectNodegetCar(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.ObjectNodegetCar(Car car, java.util.Locale locale)Get a JSON representation of a Car.com.fasterxml.jackson.databind.node.ObjectNodegetEngine(java.lang.String name, java.util.Locale locale, int id)Get the JSON representation of an Engine.com.fasterxml.jackson.databind.node.ObjectNodegetEngine(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.ObjectNodegetEngine(Engine engine, java.util.Locale locale)Get the JSON representation of an Engine.com.fasterxml.jackson.databind.node.ObjectNodegetLocation(java.lang.String name, java.util.Locale locale, int id)Get the JSON representation of a Location.com.fasterxml.jackson.databind.node.ObjectNodegetLocation(Location location, java.util.Locale locale)Get the JSON representation of a Location.com.fasterxml.jackson.databind.node.ObjectNodegetRollingStock(RollingStock rs, java.util.Locale locale)com.fasterxml.jackson.databind.node.ObjectNodegetRSLocation(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.ObjectNodegetRSTrack(Track track, java.util.Locale locale)Get a Track in JSON for use in rolling stock or train.com.fasterxml.jackson.databind.node.ObjectNodegetTrack(Track track, java.util.Locale locale)Get a Track in JSON.com.fasterxml.jackson.databind.node.ObjectNodegetTrain(java.lang.String name, java.util.Locale locale, int id)Get the JSON representation of a Train.com.fasterxml.jackson.databind.node.ObjectNodegetTrain(Train train, java.util.Locale locale)Get the JSON representation of a Train.com.fasterxml.jackson.databind.node.ArrayNodegetTrains(java.util.Locale locale)Get all trains.
-
-
-
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 Carlocale- the client's localeid- 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 Enginelocale- 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 Enginedata- the JSON data fromgetRollingStock(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 Enginelocale- the client's localeid- 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 Carlocale- 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 Cardata- the JSON data fromgetRollingStock(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 locationlocale- 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 locationlocale- the client's localeid- 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 getlocale- 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 locationlocale- 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 getlocale- the client's locale- Returns:
- a JSON representation of the track
-
getRollingStock
public com.fasterxml.jackson.databind.node.ObjectNode getRollingStock(@Nonnull RollingStock rs, java.util.Locale locale)
-
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 trainlocale- 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 trainlocale- the client's localeid- 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
-
-