Package jmri.server.json.operations
Class JsonUtil
java.lang.Object
jmri.server.json.operations.JsonUtil
Utilities used by JSON services for Operations
-
Constructor Summary
ConstructorsConstructorDescriptionJsonUtil(com.fasterxml.jackson.databind.ObjectMapper mapper) Create utilities. -
Method Summary
Modifier and TypeMethodDescriptioncom.fasterxml.jackson.databind.node.ObjectNodeGet the JSON representation of a Car.com.fasterxml.jackson.databind.node.ObjectNodeGet a JSON representation of a Car.com.fasterxml.jackson.databind.node.ObjectNodeGet a JSON representation of a Car.com.fasterxml.jackson.databind.node.ObjectNodeGet the JSON representation of an Engine.com.fasterxml.jackson.databind.node.ObjectNodeGet the JSON representation of an Engine.com.fasterxml.jackson.databind.node.ObjectNodeGet the JSON representation of an Engine.com.fasterxml.jackson.databind.node.ObjectNodegetLocation(String name, Locale locale, int id) Get the JSON representation of a Location.com.fasterxml.jackson.databind.node.ObjectNodegetLocation(Location location, Locale locale) Get the JSON representation of a Location.com.fasterxml.jackson.databind.node.ObjectNodegetRollingStock(RollingStock rs, Locale locale) com.fasterxml.jackson.databind.node.ObjectNodegetRSLocation(Location location, Locale locale) Get the JSON representation of a Location for use in rolling stock or train.com.fasterxml.jackson.databind.node.ObjectNodegetRSTrack(Track track, Locale locale) Get a Track in JSON for use in rolling stock or train.com.fasterxml.jackson.databind.node.ObjectNodeGet a Track in JSON.com.fasterxml.jackson.databind.node.ObjectNodeGet the JSON representation of a Train.com.fasterxml.jackson.databind.node.ObjectNodeGet the JSON representation of a Train.com.fasterxml.jackson.databind.node.ArrayNodeGet all trains.
-
Constructor Details
-
JsonUtil
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 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
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, 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(String name, 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
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, 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, 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(String name, 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
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, 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
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, Locale locale) -
getTrain
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(String name, 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
Get all trains.- Parameters:
locale- the client's locale- Returns:
- an array of all trains
-