Skip to content

Commit

Permalink
frontend: serialise Java List objects as JSON List
Browse files Browse the repository at this point in the history
Motivation:

Various JAX-RS resources return a List as value.

If the returned Java List happens to be a ArrayList then it is
serialised as a JSON Object with the list being the value of some
unspecified keyword; e.g.,

    { "List" : [ item-1, item-2, ... ] }

JSON supports returning lists, which is a better fit for describing a
Java List; e.g.,

    [ item-1, item-2, ... ]

Currently there is inconsistent behaviour between different
implementations of List.  For example, an ImmutableList would be
serialised as a JSON List.

Modification:

Update objectmapper to switch off the WRAP_ROOT_VALUE feature for
ArrayList items.

Result:

The JSON output for the following requests is updated to return a JSON
List rather than a JSON Object that wraps a list.

    GET /api/v1/alarms
    GET /api/v1/billing/grid/histograms
    GET /api/v1/selection/links
    GET /api/v1/selection/partitions
    GET /api/v1/selection/poolgroups
    GET /api/v1/selection/pools
    GET /api/v1/selection/unitgroups
    GET /api/v1/selection/units
    POST /api/v1/selection/match

Target: master
Require-notes: no
Require-book: no
Patch: https://rb.dcache.org/r/10542/
Acked-by: Tigran Mkrtchyan
Acked-by: Albert Rossi
  • Loading branch information
paulmillar committed Oct 16, 2017
1 parent 63d8375 commit 8a53321
Showing 1 changed file with 0 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ private static ObjectMapper createCombinedObjectMapper()
{
return new ObjectMapper()
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false)
.configure(SerializationFeature.WRAP_ROOT_VALUE, true)
.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)

Expand Down

0 comments on commit 8a53321

Please sign in to comment.