Jetty
  1. Jetty
  2. JETTY-325

Ability to publish already serializes JSON messages

    Details

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

      Description

      We have our own JSON serializer, but there is no way to publish an already formatted message. Can we have maybe a Channel.publishRaw() or Channel.publishJson() to do this?

        Activity

        Hide
        Greg Wilkins added a comment -

        I think this jira's title should be changed to "write some bloody javadoc" !-)

        Look at the innerclass JSON.Literal

        If our JSON generator finds and instance of JSON.Literal at any point in
        the Object graph, then it will use the literal JSON included in the instance
        instead of generating new JSON content.

        I will improve the javadoc for this, although there is a tiny bit about it
        in the JSON class already.

        Show
        Greg Wilkins added a comment - I think this jira's title should be changed to "write some bloody javadoc" !-) Look at the innerclass JSON.Literal If our JSON generator finds and instance of JSON.Literal at any point in the Object graph, then it will use the literal JSON included in the instance instead of generating new JSON content. I will improve the javadoc for this, although there is a tiny bit about it in the JSON class already.
        Hide
        Stefan Arentz added a comment -

        JSON.Literal works when I send data to remote clients. Thanks

        But, there is a problem: any installed datafilter on the server side will then receive the JSON.Literal instead of a parsed representation. This is rather problematic for server side clients. Shall I file a bug for that?

        Show
        Stefan Arentz added a comment - JSON.Literal works when I send data to remote clients. Thanks But, there is a problem: any installed datafilter on the server side will then receive the JSON.Literal instead of a parsed representation. This is rather problematic for server side clients. Shall I file a bug for that?
        Hide
        Stefan Arentz added a comment -

        So, instead of doing this:

                    JsonSerializer serializer = new JsonSerializer();
                    String json = serializer.serialize(object);
                    channel.publish(new JSON.Literal(json), null);
        

        I'm now doing this:

                    JsonSerializer serializer = new JsonSerializer();
                    String json = serializer.serialize(object);
                    channel.publish(JSON.parse(json), null);
        

        WHich is not really optimal

        S.

        Show
        Stefan Arentz added a comment - So, instead of doing this: JsonSerializer serializer = new JsonSerializer(); String json = serializer.serialize(object); channel.publish( new JSON.Literal(json), null ); I'm now doing this: JsonSerializer serializer = new JsonSerializer(); String json = serializer.serialize(object); channel.publish(JSON.parse(json), null ); WHich is not really optimal S.
        Hide
        Greg Wilkins added a comment -

        Stefan,

        don't create a new bug, this one will do to track it.

        I'll have to think about this, as I want to avoid expanding all JSON literals unless
        they need to be expanded - else it kind of negates the purpose.

        For your example, the extra parse cannot be avoided, but it would be good to
        avoid the additional generation phase.

        This could be done by having server side clients doing and parse of the literals, but
        that still leaves the filters as being an issue.

        The solution may be to use a JSONMap, which is just normal map except that
        when a get is done on a JSON literal, it is expanded..... need to think a bit more on
        this one.

        Show
        Greg Wilkins added a comment - Stefan, don't create a new bug, this one will do to track it. I'll have to think about this, as I want to avoid expanding all JSON literals unless they need to be expanded - else it kind of negates the purpose. For your example, the extra parse cannot be avoided, but it would be good to avoid the additional generation phase. This could be done by having server side clients doing and parse of the literals, but that still leaves the filters as being an issue. The solution may be to use a JSONMap, which is just normal map except that when a get is done on a JSON literal, it is expanded..... need to think a bit more on this one.
        Hide
        Greg Wilkins added a comment -

        I have resolved this by having the json filter base class detect literal JSON and parse it to objects before filtering it.

        Show
        Greg Wilkins added a comment - I have resolved this by having the json filter base class detect literal JSON and parse it to objects before filtering it.

          People

          • Assignee:
            Greg Wilkins
            Reporter:
            Stefan Arentz
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: