Jackson JSON Processor
  1. Jackson JSON Processor
  2. JACKSON-128

allow pretty printing to be enabled using a query argument with JAXRS?

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Just a thought; after using Jackson on some JAXRS beans in RestMQ, things look great...

      $ curl -Haccept:application/json http://localhost:8080/
      {"resources":[{"name":"queues","uri":"/queues"},{"name":"topics","uri":"/topics"}]}
      

      Though it might be nice to enable pretty printing somehow (the JacksonJsonProvider could be injected with an optional HTTP query argument maybe?) so you could do something like this...

      $ curl -Haccept:application/json http://localhost:8080/?pretty=true
      {
        "resources":[
           {"name":"queues",
              "uri":"/queues"},
           {"name":"topics",
              "uri":"/topics"}]
      }
      

      without having to add the processing of the query arguments to every method which returns JSON objects etc

        Activity

        Hide
        Tatu Saloranta added a comment -

        It is already possible to enable pretty-printing (I do that myself for test deployments); for this you need to configure ObjectMapper object. And that can be done either by registering Jackson with properly config'ed instance, a la:
        (when using sub-class of Application)


        @Override
        public Set<Object> getSingletons()

        { ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); singletons.add(new JacksonJsonProvider(mapper)); }

        or by injecting ObjectMapper via provider (if you don't control adding of JacksonJsonProvider)

        Would these work? They need to be added to FAQ at any rate.

        Also: if you can think of more convenient ways to do this (I know you have bit more experience as a Jersey user than I do, so it seems likely!), those can definitely be added. Current provider is just the first stab at trying to provider something useful.

        Show
        Tatu Saloranta added a comment - It is already possible to enable pretty-printing (I do that myself for test deployments); for this you need to configure ObjectMapper object. And that can be done either by registering Jackson with properly config'ed instance, a la: (when using sub-class of Application) — @Override public Set<Object> getSingletons() { ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); singletons.add(new JacksonJsonProvider(mapper)); } — or by injecting ObjectMapper via provider (if you don't control adding of JacksonJsonProvider) Would these work? They need to be added to FAQ at any rate. Also: if you can think of more convenient ways to do this (I know you have bit more experience as a Jersey user than I do, so it seems likely!), those can definitely be added. Current provider is just the first stab at trying to provider something useful.
        Hide
        Tatu Saloranta added a comment -

        I think that ultimately handling of query parameters falls outside scope of Jackson, so I will close this specific issue.
        However it's worth noting that more support has been added to allow such dynamic enabling of pretty printing: specifically, JACKSON-316 allows ability to enable/disable pretty-printing on per-call basis, not just for the whole ObjectMapper or JsonFactory.

        Show
        Tatu Saloranta added a comment - I think that ultimately handling of query parameters falls outside scope of Jackson, so I will close this specific issue. However it's worth noting that more support has been added to allow such dynamic enabling of pretty printing: specifically, JACKSON-316 allows ability to enable/disable pretty-printing on per-call basis, not just for the whole ObjectMapper or JsonFactory.

          People

          • Assignee:
            Tatu Saloranta
            Reporter:
            james strachan
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: