You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Gary Gregory <ga...@gmail.com> on 2014/04/01 14:45:22 UTC

LOG4J2-583, XML and JSON unmarshalling

I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP socket
servers unmarhsal XML log events.

This is "easy" for XML because when you have a stream of bytes and you know
its encoding, you can look for the end of an event by looking for its
closing tag: </Event>. Right now, my XML processing code, looks for the end
tag and feeds JAXB a substring from the buffer. Easy. Done.

Not so much with JSON. You cannot use the same hack, there is no end tag.
All you have is an "end of object" closing bracket "}" which looks the same
as the closing marker for all other objects.

So it looks like I would need to hook in a little deeper into a JSON
unmarshalling framework to extract each JSON log events as I see them.

Any thoughts here?

Gary

-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Nick Williams <ni...@nicholaswilliams.net>.
That would work if he was parsing the JSON manually, which is itself an extremely complex thing to do. It sounds like he's using Jackson—and rightly so. I'm not entirely sure how to do this with Jackson, but I help out with the development over there from time to time, and I can ask the mailing list for feedback when I get home tonight.

Nick

On Apr 1, 2014, at 10:07 AM, Matt Sicker wrote:

> Keep a stack of {'s and pop them when you get a }. Like a deterministic pushdown automaton.
> 
> 
> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP socket servers unmarhsal XML log events.
> 
> This is "easy" for XML because when you have a stream of bytes and you know its encoding, you can look for the end of an event by looking for its closing tag: </Event>. Right now, my XML processing code, looks for the end tag and feeds JAXB a substring from the buffer. Easy. Done.
> 
> Not so much with JSON. You cannot use the same hack, there is no end tag. All you have is an "end of object" closing bracket "}" which looks the same as the closing marker for all other objects.
> 
> So it looks like I would need to hook in a little deeper into a JSON unmarshalling framework to extract each JSON log events as I see them.
> 
> Any thoughts here?
> 
> Gary
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>


Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Matt Sicker <bo...@gmail.com>.
It's amusing that both Jackson and Woodstox are both FasterXML projects.
You'd think there'd be some code sharing going on? Or is FasterXML more
like Apache or Codehaus?


On 1 April 2014 15:49, Ralph Goers <ra...@dslextreme.com> wrote:

> I just did this the other day for both XML and JSON.
>
> For XML I did:
>
>     public static TransactionRequest deserialize(String xmlFile) {
>         try {
>             XmlMapper mapper = new XmlMapper();
>             InputStream stream = new FileInputStream(xmlFile);
>             return mapper.readValue(stream, TransactionRequest.class);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>     public static TransactionRequest deserialize(String xmlFile) {
>         try {
>             XmlMapper mapper = new XmlMapper();
>             InputStream stream = new FileInputStream(xmlFile);
>             return mapper.readValue(stream, TransactionRequest.class);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>
> Where needed I used things like:
>
>     @JacksonXmlProperty(localName = "return")
>     private PostSale creditCardReturn;
>
> and
>
>     @JacksonXmlProperty(isAttribute = true)
>
> For JSON I did
>
>     public static JSONRequest deserialize(String json)
>     {
>         try
>         {
>             ObjectMapper mapper = new ObjectMapper();
>             return mapper.readValue(json, JSONRequest.class);
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>
> and
>
>     public String serialize()
>     {
>         try
>         {
>             final ObjectMapper mapper = new ObjectMapper();
>             return mapper.writeValueAsString(this);
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>
> HTH,
>
> Ralph
>
>
> On Apr 1, 2014, at 1:05 PM, Gary Gregory <ga...@gmail.com> wrote:
>
> Well... so much for Jackson making my life easy. Jackson says it
> "supports" JAXB annotations but that must be only for the simplest cases.
> Jackson does not work with the JAXB annotations I used on Log4jLogEvents.
> This suppose this is not surprising. Back to the drawing board...
>
> Gary
>
>
> On Tue, Apr 1, 2014 at 12:05 PM, Gary Gregory <ga...@gmail.com>wrote:
>
>> All good ideas, thank you. The JSON API I know best is GSON, which let's
>> you listen to objects opening and closing. Maybe Jackson has something like
>> that... I'll have to dig in.
>>
>> Gary
>>
>>
>> On Tue, Apr 1, 2014 at 11:14 AM, Ralph Goers <ra...@dslextreme.com>wrote:
>>
>>> So you are hacking the stream before passing it to the unmarshalling
>>> framework?  Then you will have to keep track of the ‘{‘ and ‘}’ characters
>>> yourself, either with the stack Matt suggests or as a counter.
>>>
>>> Ralph
>>>
>>> On Apr 1, 2014, at 8:07 AM, Matt Sicker <bo...@gmail.com> wrote:
>>>
>>> Keep a stack of {'s and pop them when you get a }. Like a deterministic
>>> pushdown automaton.
>>>
>>>
>>> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
>>>
>>>> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP
>>>> socket servers unmarhsal XML log events.
>>>>
>>>> This is "easy" for XML because when you have a stream of bytes and you
>>>> know its encoding, you can look for the end of an event by looking for its
>>>> closing tag: </Event>. Right now, my XML processing code, looks for the end
>>>> tag and feeds JAXB a substring from the buffer. Easy. Done.
>>>>
>>>> Not so much with JSON. You cannot use the same hack, there is no end
>>>> tag. All you have is an "end of object" closing bracket "}" which looks the
>>>> same as the closing marker for all other objects.
>>>>
>>>> So it looks like I would need to hook in a little deeper into a JSON
>>>> unmarshalling framework to extract each JSON log events as I see them.
>>>>
>>>> Any thoughts here?
>>>>
>>>> Gary
>>>>
>>>> --
>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>> Blog: http://garygregory.wordpress.com
>>>> Home: http://garygregory.com/
>>>> Tweet! http://twitter.com/GaryGregory
>>>>
>>>
>>>
>>>
>>> --
>>> Matt Sicker <bo...@gmail.com>
>>>
>>>
>>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
>
>


-- 
Matt Sicker <bo...@gmail.com>

Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Ralph Goers <ra...@dslextreme.com>.
I have both examples there.

Ralph

On Apr 1, 2014, at 1:57 PM, Matt Sicker <bo...@gmail.com> wrote:

> Is that for the XML or JSON mapping?
> 
> 
> On 1 April 2014 15:55, Ralph Goers <ra...@dslextreme.com> wrote:
> Also, with Jackson you only have to annotate things where the normal mapping doesn’t do what you want. For example, by default everything will be an element. You need to annotate it if you want it to be an attribute.
> 
> 
> On Apr 1, 2014, at 1:52 PM, Ralph Goers <ra...@dslextreme.com> wrote:
> 
>> Oops - For XML the serialization is
>> 
>>     public void serialize(OutputStream stream) {
>>         try {
>>             final XmlMapper mapper = new XmlMapper();
>>             mapper.writeValue(stream, this);
>>         } catch (Exception ex) {
>>             ex.printStackTrace();
>>         }
>>     }
>> 
>> 
>> On Apr 1, 2014, at 1:49 PM, Ralph Goers <ra...@dslextreme.com> wrote:
>> 
>>> I just did this the other day for both XML and JSON.  
>>> 
>>> For XML I did:
>>> 
>>>     public static TransactionRequest deserialize(String xmlFile) {
>>>         try {
>>>             XmlMapper mapper = new XmlMapper();
>>>             InputStream stream = new FileInputStream(xmlFile);
>>>             return mapper.readValue(stream, TransactionRequest.class);
>>>         } catch (Exception ex) {
>>>             ex.printStackTrace();
>>>         }
>>>         return null;
>>>     }
>>>     public static TransactionRequest deserialize(String xmlFile) {
>>>         try {
>>>             XmlMapper mapper = new XmlMapper();
>>>             InputStream stream = new FileInputStream(xmlFile);
>>>             return mapper.readValue(stream, TransactionRequest.class);
>>>         } catch (Exception ex) {
>>>             ex.printStackTrace();
>>>         }
>>>         return null;
>>>     }
>>> 
>>> Where needed I used things like:
>>> 
>>>     @JacksonXmlProperty(localName = "return")
>>>     private PostSale creditCardReturn;
>>> 
>>> and 
>>> 
>>>     @JacksonXmlProperty(isAttribute = true)
>>> 
>>> For JSON I did
>>> 
>>>     public static JSONRequest deserialize(String json)
>>>     {
>>>         try
>>>         {
>>>             ObjectMapper mapper = new ObjectMapper();
>>>             return mapper.readValue(json, JSONRequest.class);
>>>         }
>>>         catch (Exception ex)
>>>         {
>>>             ex.printStackTrace();
>>>         }
>>>         return null;
>>>     }
>>> 
>>> and
>>> 
>>>     public String serialize()
>>>     {
>>>         try
>>>         {
>>>             final ObjectMapper mapper = new ObjectMapper();
>>>             return mapper.writeValueAsString(this);
>>>         }
>>>         catch (Exception ex)
>>>         {
>>>             ex.printStackTrace();
>>>         }
>>>         return null;
>>>     }
>>> 
>>> HTH,
>>> 
>>> Ralph
>>> 
>>> 
>>> On Apr 1, 2014, at 1:05 PM, Gary Gregory <ga...@gmail.com> wrote:
>>> 
>>>> Well... so much for Jackson making my life easy. Jackson says it "supports" JAXB annotations but that must be only for the simplest cases. Jackson does not work with the JAXB annotations I used on Log4jLogEvents. This suppose this is not surprising. Back to the drawing board...
>>>> 
>>>> Gary
>>>> 
>>>> 
>>>> On Tue, Apr 1, 2014 at 12:05 PM, Gary Gregory <ga...@gmail.com> wrote:
>>>> All good ideas, thank you. The JSON API I know best is GSON, which let's you listen to objects opening and closing. Maybe Jackson has something like that... I'll have to dig in.
>>>> 
>>>> Gary
>>>> 
>>>> 
>>>> On Tue, Apr 1, 2014 at 11:14 AM, Ralph Goers <ra...@dslextreme.com> wrote:
>>>> So you are hacking the stream before passing it to the unmarshalling framework?  Then you will have to keep track of the ‘{‘ and ‘}’ characters yourself, either with the stack Matt suggests or as a counter.
>>>> 
>>>> Ralph
>>>> 
>>>> On Apr 1, 2014, at 8:07 AM, Matt Sicker <bo...@gmail.com> wrote:
>>>> 
>>>>> Keep a stack of {'s and pop them when you get a }. Like a deterministic pushdown automaton.
>>>>> 
>>>>> 
>>>>> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
>>>>> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP socket servers unmarhsal XML log events.
>>>>> 
>>>>> This is "easy" for XML because when you have a stream of bytes and you know its encoding, you can look for the end of an event by looking for its closing tag: </Event>. Right now, my XML processing code, looks for the end tag and feeds JAXB a substring from the buffer. Easy. Done.
>>>>> 
>>>>> Not so much with JSON. You cannot use the same hack, there is no end tag. All you have is an "end of object" closing bracket "}" which looks the same as the closing marker for all other objects.
>>>>> 
>>>>> So it looks like I would need to hook in a little deeper into a JSON unmarshalling framework to extract each JSON log events as I see them.
>>>>> 
>>>>> Any thoughts here?
>>>>> 
>>>>> Gary
>>>>> 
>>>>> -- 
>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>>>>> Java Persistence with Hibernate, Second Edition
>>>>> JUnit in Action, Second Edition
>>>>> Spring Batch in Action
>>>>> Blog: http://garygregory.wordpress.com 
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>>> 
>>>>> 
>>>>> 
>>>>> -- 
>>>>> Matt Sicker <bo...@gmail.com>
>>>> 
>>>> 
>>>> 
>>>> 
>>>> -- 
>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>>>> Java Persistence with Hibernate, Second Edition
>>>> JUnit in Action, Second Edition
>>>> Spring Batch in Action
>>>> Blog: http://garygregory.wordpress.com 
>>>> Home: http://garygregory.com/
>>>> Tweet! http://twitter.com/GaryGregory
>>>> 
>>>> 
>>>> 
>>>> -- 
>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>>>> Java Persistence with Hibernate, Second Edition
>>>> JUnit in Action, Second Edition
>>>> Spring Batch in Action
>>>> Blog: http://garygregory.wordpress.com 
>>>> Home: http://garygregory.com/
>>>> Tweet! http://twitter.com/GaryGregory
>>> 
>> 
> 
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>


Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Matt Sicker <bo...@gmail.com>.
Actually, that brought up an idea I just had. Since the XML parsing log4j's
config does isn't strict about whether you use an attribute or nested
element (which sounds like it meshes nicely with JSON), maybe the parsing
can be unified somewhat? I know I made some progress at de-duplicating code
in the three FooConfiguration classes, and there's already the Node/etc.
abstraction for the parsed tree.


On 1 April 2014 15:57, Matt Sicker <bo...@gmail.com> wrote:

> Is that for the XML or JSON mapping?
>
>
> On 1 April 2014 15:55, Ralph Goers <ra...@dslextreme.com> wrote:
>
>> Also, with Jackson you only have to annotate things where the normal
>> mapping doesn’t do what you want. For example, by default everything will
>> be an element. You need to annotate it if you want it to be an attribute.
>>
>>
>> On Apr 1, 2014, at 1:52 PM, Ralph Goers <ra...@dslextreme.com>
>> wrote:
>>
>> Oops - For XML the serialization is
>>
>>     public void serialize(OutputStream stream) {
>>         try {
>>             final XmlMapper mapper = new XmlMapper();
>>             mapper.writeValue(stream, this);
>>         } catch (Exception ex) {
>>             ex.printStackTrace();
>>         }
>>     }
>>
>>
>> On Apr 1, 2014, at 1:49 PM, Ralph Goers <ra...@dslextreme.com>
>> wrote:
>>
>> I just did this the other day for both XML and JSON.
>>
>> For XML I did:
>>
>>     public static TransactionRequest deserialize(String xmlFile) {
>>         try {
>>             XmlMapper mapper = new XmlMapper();
>>             InputStream stream = new FileInputStream(xmlFile);
>>             return mapper.readValue(stream, TransactionRequest.class);
>>         } catch (Exception ex) {
>>             ex.printStackTrace();
>>         }
>>         return null;
>>     }
>>     public static TransactionRequest deserialize(String xmlFile) {
>>         try {
>>             XmlMapper mapper = new XmlMapper();
>>             InputStream stream = new FileInputStream(xmlFile);
>>             return mapper.readValue(stream, TransactionRequest.class);
>>         } catch (Exception ex) {
>>             ex.printStackTrace();
>>         }
>>         return null;
>>     }
>>
>> Where needed I used things like:
>>
>>     @JacksonXmlProperty(localName = "return")
>>     private PostSale creditCardReturn;
>>
>> and
>>
>>     @JacksonXmlProperty(isAttribute = true)
>>
>> For JSON I did
>>
>>     public static JSONRequest deserialize(String json)
>>     {
>>         try
>>         {
>>             ObjectMapper mapper = new ObjectMapper();
>>             return mapper.readValue(json, JSONRequest.class);
>>         }
>>         catch (Exception ex)
>>         {
>>             ex.printStackTrace();
>>         }
>>         return null;
>>     }
>>
>> and
>>
>>     public String serialize()
>>     {
>>         try
>>         {
>>             final ObjectMapper mapper = new ObjectMapper();
>>             return mapper.writeValueAsString(this);
>>         }
>>         catch (Exception ex)
>>         {
>>             ex.printStackTrace();
>>         }
>>         return null;
>>     }
>>
>> HTH,
>>
>> Ralph
>>
>>
>> On Apr 1, 2014, at 1:05 PM, Gary Gregory <ga...@gmail.com> wrote:
>>
>> Well... so much for Jackson making my life easy. Jackson says it
>> "supports" JAXB annotations but that must be only for the simplest cases.
>> Jackson does not work with the JAXB annotations I used on Log4jLogEvents.
>> This suppose this is not surprising. Back to the drawing board...
>>
>> Gary
>>
>>
>> On Tue, Apr 1, 2014 at 12:05 PM, Gary Gregory <ga...@gmail.com>wrote:
>>
>>> All good ideas, thank you. The JSON API I know best is GSON, which let's
>>> you listen to objects opening and closing. Maybe Jackson has something like
>>> that... I'll have to dig in.
>>>
>>> Gary
>>>
>>>
>>> On Tue, Apr 1, 2014 at 11:14 AM, Ralph Goers <ralph.goers@dslextreme.com
>>> > wrote:
>>>
>>>> So you are hacking the stream before passing it to the unmarshalling
>>>> framework?  Then you will have to keep track of the ‘{‘ and ‘}’ characters
>>>> yourself, either with the stack Matt suggests or as a counter.
>>>>
>>>> Ralph
>>>>
>>>> On Apr 1, 2014, at 8:07 AM, Matt Sicker <bo...@gmail.com> wrote:
>>>>
>>>> Keep a stack of {'s and pop them when you get a }. Like a deterministic
>>>> pushdown automaton.
>>>>
>>>>
>>>> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
>>>>
>>>>> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP
>>>>> socket servers unmarhsal XML log events.
>>>>>
>>>>> This is "easy" for XML because when you have a stream of bytes and you
>>>>> know its encoding, you can look for the end of an event by looking for its
>>>>> closing tag: </Event>. Right now, my XML processing code, looks for the end
>>>>> tag and feeds JAXB a substring from the buffer. Easy. Done.
>>>>>
>>>>> Not so much with JSON. You cannot use the same hack, there is no end
>>>>> tag. All you have is an "end of object" closing bracket "}" which looks the
>>>>> same as the closing marker for all other objects.
>>>>>
>>>>> So it looks like I would need to hook in a little deeper into a JSON
>>>>> unmarshalling framework to extract each JSON log events as I see them.
>>>>>
>>>>> Any thoughts here?
>>>>>
>>>>> Gary
>>>>>
>>>>> --
>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>> Blog: http://garygregory.wordpress.com
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Matt Sicker <bo...@gmail.com>
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>>
>>
>>
>>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>



-- 
Matt Sicker <bo...@gmail.com>

Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Matt Sicker <bo...@gmail.com>.
Is that for the XML or JSON mapping?


On 1 April 2014 15:55, Ralph Goers <ra...@dslextreme.com> wrote:

> Also, with Jackson you only have to annotate things where the normal
> mapping doesn’t do what you want. For example, by default everything will
> be an element. You need to annotate it if you want it to be an attribute.
>
>
> On Apr 1, 2014, at 1:52 PM, Ralph Goers <ra...@dslextreme.com>
> wrote:
>
> Oops - For XML the serialization is
>
>     public void serialize(OutputStream stream) {
>         try {
>             final XmlMapper mapper = new XmlMapper();
>             mapper.writeValue(stream, this);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>     }
>
>
> On Apr 1, 2014, at 1:49 PM, Ralph Goers <ra...@dslextreme.com>
> wrote:
>
> I just did this the other day for both XML and JSON.
>
> For XML I did:
>
>     public static TransactionRequest deserialize(String xmlFile) {
>         try {
>             XmlMapper mapper = new XmlMapper();
>             InputStream stream = new FileInputStream(xmlFile);
>             return mapper.readValue(stream, TransactionRequest.class);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>     public static TransactionRequest deserialize(String xmlFile) {
>         try {
>             XmlMapper mapper = new XmlMapper();
>             InputStream stream = new FileInputStream(xmlFile);
>             return mapper.readValue(stream, TransactionRequest.class);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>
> Where needed I used things like:
>
>     @JacksonXmlProperty(localName = "return")
>     private PostSale creditCardReturn;
>
> and
>
>     @JacksonXmlProperty(isAttribute = true)
>
> For JSON I did
>
>     public static JSONRequest deserialize(String json)
>     {
>         try
>         {
>             ObjectMapper mapper = new ObjectMapper();
>             return mapper.readValue(json, JSONRequest.class);
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>
> and
>
>     public String serialize()
>     {
>         try
>         {
>             final ObjectMapper mapper = new ObjectMapper();
>             return mapper.writeValueAsString(this);
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>
> HTH,
>
> Ralph
>
>
> On Apr 1, 2014, at 1:05 PM, Gary Gregory <ga...@gmail.com> wrote:
>
> Well... so much for Jackson making my life easy. Jackson says it
> "supports" JAXB annotations but that must be only for the simplest cases.
> Jackson does not work with the JAXB annotations I used on Log4jLogEvents.
> This suppose this is not surprising. Back to the drawing board...
>
> Gary
>
>
> On Tue, Apr 1, 2014 at 12:05 PM, Gary Gregory <ga...@gmail.com>wrote:
>
>> All good ideas, thank you. The JSON API I know best is GSON, which let's
>> you listen to objects opening and closing. Maybe Jackson has something like
>> that... I'll have to dig in.
>>
>> Gary
>>
>>
>> On Tue, Apr 1, 2014 at 11:14 AM, Ralph Goers <ra...@dslextreme.com>wrote:
>>
>>> So you are hacking the stream before passing it to the unmarshalling
>>> framework?  Then you will have to keep track of the ‘{‘ and ‘}’ characters
>>> yourself, either with the stack Matt suggests or as a counter.
>>>
>>> Ralph
>>>
>>> On Apr 1, 2014, at 8:07 AM, Matt Sicker <bo...@gmail.com> wrote:
>>>
>>> Keep a stack of {'s and pop them when you get a }. Like a deterministic
>>> pushdown automaton.
>>>
>>>
>>> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
>>>
>>>> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP
>>>> socket servers unmarhsal XML log events.
>>>>
>>>> This is "easy" for XML because when you have a stream of bytes and you
>>>> know its encoding, you can look for the end of an event by looking for its
>>>> closing tag: </Event>. Right now, my XML processing code, looks for the end
>>>> tag and feeds JAXB a substring from the buffer. Easy. Done.
>>>>
>>>> Not so much with JSON. You cannot use the same hack, there is no end
>>>> tag. All you have is an "end of object" closing bracket "}" which looks the
>>>> same as the closing marker for all other objects.
>>>>
>>>> So it looks like I would need to hook in a little deeper into a JSON
>>>> unmarshalling framework to extract each JSON log events as I see them.
>>>>
>>>> Any thoughts here?
>>>>
>>>> Gary
>>>>
>>>> --
>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>> Blog: http://garygregory.wordpress.com
>>>> Home: http://garygregory.com/
>>>> Tweet! http://twitter.com/GaryGregory
>>>>
>>>
>>>
>>>
>>> --
>>> Matt Sicker <bo...@gmail.com>
>>>
>>>
>>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
>
>
>
>


-- 
Matt Sicker <bo...@gmail.com>

Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Ralph Goers <ra...@dslextreme.com>.
Also, with Jackson you only have to annotate things where the normal mapping doesn’t do what you want. For example, by default everything will be an element. You need to annotate it if you want it to be an attribute.


On Apr 1, 2014, at 1:52 PM, Ralph Goers <ra...@dslextreme.com> wrote:

> Oops - For XML the serialization is
> 
>     public void serialize(OutputStream stream) {
>         try {
>             final XmlMapper mapper = new XmlMapper();
>             mapper.writeValue(stream, this);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>     }
> 
> 
> On Apr 1, 2014, at 1:49 PM, Ralph Goers <ra...@dslextreme.com> wrote:
> 
>> I just did this the other day for both XML and JSON.  
>> 
>> For XML I did:
>> 
>>     public static TransactionRequest deserialize(String xmlFile) {
>>         try {
>>             XmlMapper mapper = new XmlMapper();
>>             InputStream stream = new FileInputStream(xmlFile);
>>             return mapper.readValue(stream, TransactionRequest.class);
>>         } catch (Exception ex) {
>>             ex.printStackTrace();
>>         }
>>         return null;
>>     }
>>     public static TransactionRequest deserialize(String xmlFile) {
>>         try {
>>             XmlMapper mapper = new XmlMapper();
>>             InputStream stream = new FileInputStream(xmlFile);
>>             return mapper.readValue(stream, TransactionRequest.class);
>>         } catch (Exception ex) {
>>             ex.printStackTrace();
>>         }
>>         return null;
>>     }
>> 
>> Where needed I used things like:
>> 
>>     @JacksonXmlProperty(localName = "return")
>>     private PostSale creditCardReturn;
>> 
>> and 
>> 
>>     @JacksonXmlProperty(isAttribute = true)
>> 
>> For JSON I did
>> 
>>     public static JSONRequest deserialize(String json)
>>     {
>>         try
>>         {
>>             ObjectMapper mapper = new ObjectMapper();
>>             return mapper.readValue(json, JSONRequest.class);
>>         }
>>         catch (Exception ex)
>>         {
>>             ex.printStackTrace();
>>         }
>>         return null;
>>     }
>> 
>> and
>> 
>>     public String serialize()
>>     {
>>         try
>>         {
>>             final ObjectMapper mapper = new ObjectMapper();
>>             return mapper.writeValueAsString(this);
>>         }
>>         catch (Exception ex)
>>         {
>>             ex.printStackTrace();
>>         }
>>         return null;
>>     }
>> 
>> HTH,
>> 
>> Ralph
>> 
>> 
>> On Apr 1, 2014, at 1:05 PM, Gary Gregory <ga...@gmail.com> wrote:
>> 
>>> Well... so much for Jackson making my life easy. Jackson says it "supports" JAXB annotations but that must be only for the simplest cases. Jackson does not work with the JAXB annotations I used on Log4jLogEvents. This suppose this is not surprising. Back to the drawing board...
>>> 
>>> Gary
>>> 
>>> 
>>> On Tue, Apr 1, 2014 at 12:05 PM, Gary Gregory <ga...@gmail.com> wrote:
>>> All good ideas, thank you. The JSON API I know best is GSON, which let's you listen to objects opening and closing. Maybe Jackson has something like that... I'll have to dig in.
>>> 
>>> Gary
>>> 
>>> 
>>> On Tue, Apr 1, 2014 at 11:14 AM, Ralph Goers <ra...@dslextreme.com> wrote:
>>> So you are hacking the stream before passing it to the unmarshalling framework?  Then you will have to keep track of the ‘{‘ and ‘}’ characters yourself, either with the stack Matt suggests or as a counter.
>>> 
>>> Ralph
>>> 
>>> On Apr 1, 2014, at 8:07 AM, Matt Sicker <bo...@gmail.com> wrote:
>>> 
>>>> Keep a stack of {'s and pop them when you get a }. Like a deterministic pushdown automaton.
>>>> 
>>>> 
>>>> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
>>>> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP socket servers unmarhsal XML log events.
>>>> 
>>>> This is "easy" for XML because when you have a stream of bytes and you know its encoding, you can look for the end of an event by looking for its closing tag: </Event>. Right now, my XML processing code, looks for the end tag and feeds JAXB a substring from the buffer. Easy. Done.
>>>> 
>>>> Not so much with JSON. You cannot use the same hack, there is no end tag. All you have is an "end of object" closing bracket "}" which looks the same as the closing marker for all other objects.
>>>> 
>>>> So it looks like I would need to hook in a little deeper into a JSON unmarshalling framework to extract each JSON log events as I see them.
>>>> 
>>>> Any thoughts here?
>>>> 
>>>> Gary
>>>> 
>>>> -- 
>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>>>> Java Persistence with Hibernate, Second Edition
>>>> JUnit in Action, Second Edition
>>>> Spring Batch in Action
>>>> Blog: http://garygregory.wordpress.com 
>>>> Home: http://garygregory.com/
>>>> Tweet! http://twitter.com/GaryGregory
>>>> 
>>>> 
>>>> 
>>>> -- 
>>>> Matt Sicker <bo...@gmail.com>
>>> 
>>> 
>>> 
>>> 
>>> -- 
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>>> Java Persistence with Hibernate, Second Edition
>>> JUnit in Action, Second Edition
>>> Spring Batch in Action
>>> Blog: http://garygregory.wordpress.com 
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>> 
>>> 
>>> 
>>> -- 
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>>> Java Persistence with Hibernate, Second Edition
>>> JUnit in Action, Second Edition
>>> Spring Batch in Action
>>> Blog: http://garygregory.wordpress.com 
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>> 
> 


Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Ralph Goers <ra...@dslextreme.com>.
Oops - For XML the serialization is

    public void serialize(OutputStream stream) {
        try {
            final XmlMapper mapper = new XmlMapper();
            mapper.writeValue(stream, this);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }


On Apr 1, 2014, at 1:49 PM, Ralph Goers <ra...@dslextreme.com> wrote:

> I just did this the other day for both XML and JSON.  
> 
> For XML I did:
> 
>     public static TransactionRequest deserialize(String xmlFile) {
>         try {
>             XmlMapper mapper = new XmlMapper();
>             InputStream stream = new FileInputStream(xmlFile);
>             return mapper.readValue(stream, TransactionRequest.class);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>     public static TransactionRequest deserialize(String xmlFile) {
>         try {
>             XmlMapper mapper = new XmlMapper();
>             InputStream stream = new FileInputStream(xmlFile);
>             return mapper.readValue(stream, TransactionRequest.class);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>         return null;
>     }
> 
> Where needed I used things like:
> 
>     @JacksonXmlProperty(localName = "return")
>     private PostSale creditCardReturn;
> 
> and 
> 
>     @JacksonXmlProperty(isAttribute = true)
> 
> For JSON I did
> 
>     public static JSONRequest deserialize(String json)
>     {
>         try
>         {
>             ObjectMapper mapper = new ObjectMapper();
>             return mapper.readValue(json, JSONRequest.class);
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         return null;
>     }
> 
> and
> 
>     public String serialize()
>     {
>         try
>         {
>             final ObjectMapper mapper = new ObjectMapper();
>             return mapper.writeValueAsString(this);
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         return null;
>     }
> 
> HTH,
> 
> Ralph
> 
> 
> On Apr 1, 2014, at 1:05 PM, Gary Gregory <ga...@gmail.com> wrote:
> 
>> Well... so much for Jackson making my life easy. Jackson says it "supports" JAXB annotations but that must be only for the simplest cases. Jackson does not work with the JAXB annotations I used on Log4jLogEvents. This suppose this is not surprising. Back to the drawing board...
>> 
>> Gary
>> 
>> 
>> On Tue, Apr 1, 2014 at 12:05 PM, Gary Gregory <ga...@gmail.com> wrote:
>> All good ideas, thank you. The JSON API I know best is GSON, which let's you listen to objects opening and closing. Maybe Jackson has something like that... I'll have to dig in.
>> 
>> Gary
>> 
>> 
>> On Tue, Apr 1, 2014 at 11:14 AM, Ralph Goers <ra...@dslextreme.com> wrote:
>> So you are hacking the stream before passing it to the unmarshalling framework?  Then you will have to keep track of the ‘{‘ and ‘}’ characters yourself, either with the stack Matt suggests or as a counter.
>> 
>> Ralph
>> 
>> On Apr 1, 2014, at 8:07 AM, Matt Sicker <bo...@gmail.com> wrote:
>> 
>>> Keep a stack of {'s and pop them when you get a }. Like a deterministic pushdown automaton.
>>> 
>>> 
>>> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
>>> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP socket servers unmarhsal XML log events.
>>> 
>>> This is "easy" for XML because when you have a stream of bytes and you know its encoding, you can look for the end of an event by looking for its closing tag: </Event>. Right now, my XML processing code, looks for the end tag and feeds JAXB a substring from the buffer. Easy. Done.
>>> 
>>> Not so much with JSON. You cannot use the same hack, there is no end tag. All you have is an "end of object" closing bracket "}" which looks the same as the closing marker for all other objects.
>>> 
>>> So it looks like I would need to hook in a little deeper into a JSON unmarshalling framework to extract each JSON log events as I see them.
>>> 
>>> Any thoughts here?
>>> 
>>> Gary
>>> 
>>> -- 
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>>> Java Persistence with Hibernate, Second Edition
>>> JUnit in Action, Second Edition
>>> Spring Batch in Action
>>> Blog: http://garygregory.wordpress.com 
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>> 
>>> 
>>> 
>>> -- 
>>> Matt Sicker <bo...@gmail.com>
>> 
>> 
>> 
>> 
>> -- 
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>> Java Persistence with Hibernate, Second Edition
>> JUnit in Action, Second Edition
>> Spring Batch in Action
>> Blog: http://garygregory.wordpress.com 
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>> 
>> 
>> 
>> -- 
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>> Java Persistence with Hibernate, Second Edition
>> JUnit in Action, Second Edition
>> Spring Batch in Action
>> Blog: http://garygregory.wordpress.com 
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
> 


Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Ralph Goers <ra...@dslextreme.com>.
I have no idea why it is named JacksonXmlProperty instead of JsonProperty, but it is for extended XML annotations.

Ralph

On Apr 1, 2014, at 2:37 PM, Gary Gregory <ga...@gmail.com> wrote:

> JacksonXmlProperty? Why not JsonProperty? Couldn't you then use JSON or XML? Still learning Jackson...
> 
> Gary
> 
> 
> On Tue, Apr 1, 2014 at 4:49 PM, Ralph Goers <ra...@dslextreme.com> wrote:
> I just did this the other day for both XML and JSON.  
> 
> For XML I did:
> 
>     public static TransactionRequest deserialize(String xmlFile) {
>         try {
>             XmlMapper mapper = new XmlMapper();
>             InputStream stream = new FileInputStream(xmlFile);
>             return mapper.readValue(stream, TransactionRequest.class);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>     public static TransactionRequest deserialize(String xmlFile) {
>         try {
>             XmlMapper mapper = new XmlMapper();
>             InputStream stream = new FileInputStream(xmlFile);
>             return mapper.readValue(stream, TransactionRequest.class);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>         return null;
>     }
> 
> Where needed I used things like:
> 
>     @JacksonXmlProperty(localName = "return")
>     private PostSale creditCardReturn;
> 
> and 
> 
>     @JacksonXmlProperty(isAttribute = true)
> 
> For JSON I did
> 
>     public static JSONRequest deserialize(String json)
>     {
>         try
>         {
>             ObjectMapper mapper = new ObjectMapper();
>             return mapper.readValue(json, JSONRequest.class);
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         return null;
>     }
> 
> and
> 
>     public String serialize()
>     {
>         try
>         {
>             final ObjectMapper mapper = new ObjectMapper();
>             return mapper.writeValueAsString(this);
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         return null;
>     }
> 
> HTH,
> 
> Ralph
> 
> 
> On Apr 1, 2014, at 1:05 PM, Gary Gregory <ga...@gmail.com> wrote:
> 
>> Well... so much for Jackson making my life easy. Jackson says it "supports" JAXB annotations but that must be only for the simplest cases. Jackson does not work with the JAXB annotations I used on Log4jLogEvents. This suppose this is not surprising. Back to the drawing board...
>> 
>> Gary
>> 
>> 
>> On Tue, Apr 1, 2014 at 12:05 PM, Gary Gregory <ga...@gmail.com> wrote:
>> All good ideas, thank you. The JSON API I know best is GSON, which let's you listen to objects opening and closing. Maybe Jackson has something like that... I'll have to dig in.
>> 
>> Gary
>> 
>> 
>> On Tue, Apr 1, 2014 at 11:14 AM, Ralph Goers <ra...@dslextreme.com> wrote:
>> So you are hacking the stream before passing it to the unmarshalling framework?  Then you will have to keep track of the ‘{‘ and ‘}’ characters yourself, either with the stack Matt suggests or as a counter.
>> 
>> Ralph
>> 
>> On Apr 1, 2014, at 8:07 AM, Matt Sicker <bo...@gmail.com> wrote:
>> 
>>> Keep a stack of {'s and pop them when you get a }. Like a deterministic pushdown automaton.
>>> 
>>> 
>>> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
>>> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP socket servers unmarhsal XML log events.
>>> 
>>> This is "easy" for XML because when you have a stream of bytes and you know its encoding, you can look for the end of an event by looking for its closing tag: </Event>. Right now, my XML processing code, looks for the end tag and feeds JAXB a substring from the buffer. Easy. Done.
>>> 
>>> Not so much with JSON. You cannot use the same hack, there is no end tag. All you have is an "end of object" closing bracket "}" which looks the same as the closing marker for all other objects.
>>> 
>>> So it looks like I would need to hook in a little deeper into a JSON unmarshalling framework to extract each JSON log events as I see them.
>>> 
>>> Any thoughts here?
>>> 
>>> Gary
>>> 
>>> -- 
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>>> Java Persistence with Hibernate, Second Edition
>>> JUnit in Action, Second Edition
>>> Spring Batch in Action
>>> Blog: http://garygregory.wordpress.com 
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>> 
>>> 
>>> 
>>> -- 
>>> Matt Sicker <bo...@gmail.com>
>> 
>> 
>> 
>> 
>> -- 
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>> Java Persistence with Hibernate, Second Edition
>> JUnit in Action, Second Edition
>> Spring Batch in Action
>> Blog: http://garygregory.wordpress.com 
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>> 
>> 
>> 
>> -- 
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>> Java Persistence with Hibernate, Second Edition
>> JUnit in Action, Second Edition
>> Spring Batch in Action
>> Blog: http://garygregory.wordpress.com 
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
> 
> 
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory


Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Matt Sicker <bo...@gmail.com>.
On Tuesday, 1 April 2014, Gary Gregory <ga...@gmail.com> wrote:

> Also interesting: Google GSON in on my Eclipse project CP, so it must be
> brought in... somehow...
>
> Could be mongo or couch?


> Gary
>
>
> On Tue, Apr 1, 2014 at 5:37 PM, Gary Gregory <ga...@gmail.com>wrote:
>
> JacksonXmlProperty? Why not JsonProperty? Couldn't you then use JSON or
> XML? Still learning Jackson...
>
> Gary
>
>
> On Tue, Apr 1, 2014 at 4:49 PM, Ralph Goers <ra...@dslextreme.com>wrote:
>
> I just did this the other day for both XML and JSON.
>
> For XML I did:
>
>     public static TransactionRequest deserialize(String xmlFile) {
>         try {
>             XmlMapper mapper = new XmlMapper();
>             InputStream stream = new FileInputStream(xmlFile);
>             return mapper.readValue(stream, TransactionRequest.class);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>     public static TransactionRequest deserialize(String xmlFile) {
>         try {
>             XmlMapper mapper = new XmlMapper();
>             InputStream stream = new FileInputStream(xmlFile);
>             return mapper.readValue(stream, TransactionRequest.class);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>
> Where needed I used things like:
>
>     @JacksonXmlProperty(localName = "return")
>     private PostSale creditCardReturn;
>
> and
>
>     @JacksonXmlProperty(isAttribute = true)
>
> For JSON I did
>
>     public static JSONRequest deserialize(String json)
>     {
>         try
>         {
>             ObjectMapper mapper = new ObjectMapper();
>             return mapper.readValue(json, JSONRequest.class);
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>
> and
>
>     public String serialize()
>     {
>         try
>         {
>             final ObjectMapper mapper = new ObjectMapper();
>             return mapper.writeValueAsString(this);
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>
> HTH,
>
> Ralph
>
>
> On Apr 1, 2014, at 1:05 PM, Gary Gregory <ga...@gmail.com> wrote:
>
> Well... so much for Jackson making my life easy. Jackson says it
> "supports" JAXB annotations but that must be only for the simplest cases.
> Jackson does not work with the JAXB annotations I used on Log4jLogEvents.
> This suppose this is not surprising. Back to the drawing board...
>
> Gary
>
>
> On Tue, Apr 1, 2014 at 12:05 PM, Gary Gregory <ga...@gmail.com>wrote:
>
> All good ideas, thank you. The JSON API I know best is GSON, which let's
> you listen to objects opening and closing. Maybe Jackson has something like
> that... I'll have to dig in.
>
> Gary
>
>
> On Tue, Apr 1, 2014 at 11:14 AM, Ralph Goers <ra...@dslextreme.com>wrote:
>
> So you are hacking
>
>

-- 
Matt Sicker <bo...@gmail.com>

Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Gary Gregory <ga...@gmail.com>.
Also interesting: Google GSON in on my Eclipse project CP, so it must be
brought in... somehow...

Gary


On Tue, Apr 1, 2014 at 5:37 PM, Gary Gregory <ga...@gmail.com> wrote:

> JacksonXmlProperty? Why not JsonProperty? Couldn't you then use JSON or
> XML? Still learning Jackson...
>
> Gary
>
>
> On Tue, Apr 1, 2014 at 4:49 PM, Ralph Goers <ra...@dslextreme.com>wrote:
>
>> I just did this the other day for both XML and JSON.
>>
>> For XML I did:
>>
>>     public static TransactionRequest deserialize(String xmlFile) {
>>         try {
>>             XmlMapper mapper = new XmlMapper();
>>             InputStream stream = new FileInputStream(xmlFile);
>>             return mapper.readValue(stream, TransactionRequest.class);
>>         } catch (Exception ex) {
>>             ex.printStackTrace();
>>         }
>>         return null;
>>     }
>>     public static TransactionRequest deserialize(String xmlFile) {
>>         try {
>>             XmlMapper mapper = new XmlMapper();
>>             InputStream stream = new FileInputStream(xmlFile);
>>             return mapper.readValue(stream, TransactionRequest.class);
>>         } catch (Exception ex) {
>>             ex.printStackTrace();
>>         }
>>         return null;
>>     }
>>
>> Where needed I used things like:
>>
>>     @JacksonXmlProperty(localName = "return")
>>     private PostSale creditCardReturn;
>>
>> and
>>
>>     @JacksonXmlProperty(isAttribute = true)
>>
>> For JSON I did
>>
>>     public static JSONRequest deserialize(String json)
>>     {
>>         try
>>         {
>>             ObjectMapper mapper = new ObjectMapper();
>>             return mapper.readValue(json, JSONRequest.class);
>>         }
>>         catch (Exception ex)
>>         {
>>             ex.printStackTrace();
>>         }
>>         return null;
>>     }
>>
>> and
>>
>>     public String serialize()
>>     {
>>         try
>>         {
>>             final ObjectMapper mapper = new ObjectMapper();
>>             return mapper.writeValueAsString(this);
>>         }
>>         catch (Exception ex)
>>         {
>>             ex.printStackTrace();
>>         }
>>         return null;
>>     }
>>
>> HTH,
>>
>> Ralph
>>
>>
>> On Apr 1, 2014, at 1:05 PM, Gary Gregory <ga...@gmail.com> wrote:
>>
>> Well... so much for Jackson making my life easy. Jackson says it
>> "supports" JAXB annotations but that must be only for the simplest cases.
>> Jackson does not work with the JAXB annotations I used on Log4jLogEvents.
>> This suppose this is not surprising. Back to the drawing board...
>>
>> Gary
>>
>>
>> On Tue, Apr 1, 2014 at 12:05 PM, Gary Gregory <ga...@gmail.com>wrote:
>>
>>> All good ideas, thank you. The JSON API I know best is GSON, which let's
>>> you listen to objects opening and closing. Maybe Jackson has something like
>>> that... I'll have to dig in.
>>>
>>> Gary
>>>
>>>
>>> On Tue, Apr 1, 2014 at 11:14 AM, Ralph Goers <ralph.goers@dslextreme.com
>>> > wrote:
>>>
>>>> So you are hacking the stream before passing it to the unmarshalling
>>>> framework?  Then you will have to keep track of the ‘{‘ and ‘}’ characters
>>>> yourself, either with the stack Matt suggests or as a counter.
>>>>
>>>> Ralph
>>>>
>>>> On Apr 1, 2014, at 8:07 AM, Matt Sicker <bo...@gmail.com> wrote:
>>>>
>>>> Keep a stack of {'s and pop them when you get a }. Like a deterministic
>>>> pushdown automaton.
>>>>
>>>>
>>>> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
>>>>
>>>>> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP
>>>>> socket servers unmarhsal XML log events.
>>>>>
>>>>> This is "easy" for XML because when you have a stream of bytes and you
>>>>> know its encoding, you can look for the end of an event by looking for its
>>>>> closing tag: </Event>. Right now, my XML processing code, looks for the end
>>>>> tag and feeds JAXB a substring from the buffer. Easy. Done.
>>>>>
>>>>> Not so much with JSON. You cannot use the same hack, there is no end
>>>>> tag. All you have is an "end of object" closing bracket "}" which looks the
>>>>> same as the closing marker for all other objects.
>>>>>
>>>>> So it looks like I would need to hook in a little deeper into a JSON
>>>>> unmarshalling framework to extract each JSON log events as I see them.
>>>>>
>>>>> Any thoughts here?
>>>>>
>>>>> Gary
>>>>>
>>>>> --
>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>>> Blog: http://garygregory.wordpress.com
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Matt Sicker <bo...@gmail.com>
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>>
>>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Gary Gregory <ga...@gmail.com>.
JacksonXmlProperty? Why not JsonProperty? Couldn't you then use JSON or
XML? Still learning Jackson...

Gary


On Tue, Apr 1, 2014 at 4:49 PM, Ralph Goers <ra...@dslextreme.com>wrote:

> I just did this the other day for both XML and JSON.
>
> For XML I did:
>
>     public static TransactionRequest deserialize(String xmlFile) {
>         try {
>             XmlMapper mapper = new XmlMapper();
>             InputStream stream = new FileInputStream(xmlFile);
>             return mapper.readValue(stream, TransactionRequest.class);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>     public static TransactionRequest deserialize(String xmlFile) {
>         try {
>             XmlMapper mapper = new XmlMapper();
>             InputStream stream = new FileInputStream(xmlFile);
>             return mapper.readValue(stream, TransactionRequest.class);
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>
> Where needed I used things like:
>
>     @JacksonXmlProperty(localName = "return")
>     private PostSale creditCardReturn;
>
> and
>
>     @JacksonXmlProperty(isAttribute = true)
>
> For JSON I did
>
>     public static JSONRequest deserialize(String json)
>     {
>         try
>         {
>             ObjectMapper mapper = new ObjectMapper();
>             return mapper.readValue(json, JSONRequest.class);
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>
> and
>
>     public String serialize()
>     {
>         try
>         {
>             final ObjectMapper mapper = new ObjectMapper();
>             return mapper.writeValueAsString(this);
>         }
>         catch (Exception ex)
>         {
>             ex.printStackTrace();
>         }
>         return null;
>     }
>
> HTH,
>
> Ralph
>
>
> On Apr 1, 2014, at 1:05 PM, Gary Gregory <ga...@gmail.com> wrote:
>
> Well... so much for Jackson making my life easy. Jackson says it
> "supports" JAXB annotations but that must be only for the simplest cases.
> Jackson does not work with the JAXB annotations I used on Log4jLogEvents.
> This suppose this is not surprising. Back to the drawing board...
>
> Gary
>
>
> On Tue, Apr 1, 2014 at 12:05 PM, Gary Gregory <ga...@gmail.com>wrote:
>
>> All good ideas, thank you. The JSON API I know best is GSON, which let's
>> you listen to objects opening and closing. Maybe Jackson has something like
>> that... I'll have to dig in.
>>
>> Gary
>>
>>
>> On Tue, Apr 1, 2014 at 11:14 AM, Ralph Goers <ra...@dslextreme.com>wrote:
>>
>>> So you are hacking the stream before passing it to the unmarshalling
>>> framework?  Then you will have to keep track of the ‘{‘ and ‘}’ characters
>>> yourself, either with the stack Matt suggests or as a counter.
>>>
>>> Ralph
>>>
>>> On Apr 1, 2014, at 8:07 AM, Matt Sicker <bo...@gmail.com> wrote:
>>>
>>> Keep a stack of {'s and pop them when you get a }. Like a deterministic
>>> pushdown automaton.
>>>
>>>
>>> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
>>>
>>>> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP
>>>> socket servers unmarhsal XML log events.
>>>>
>>>> This is "easy" for XML because when you have a stream of bytes and you
>>>> know its encoding, you can look for the end of an event by looking for its
>>>> closing tag: </Event>. Right now, my XML processing code, looks for the end
>>>> tag and feeds JAXB a substring from the buffer. Easy. Done.
>>>>
>>>> Not so much with JSON. You cannot use the same hack, there is no end
>>>> tag. All you have is an "end of object" closing bracket "}" which looks the
>>>> same as the closing marker for all other objects.
>>>>
>>>> So it looks like I would need to hook in a little deeper into a JSON
>>>> unmarshalling framework to extract each JSON log events as I see them.
>>>>
>>>> Any thoughts here?
>>>>
>>>> Gary
>>>>
>>>> --
>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>>> Spring Batch in Action <http://www.manning.com/templier/>
>>>> Blog: http://garygregory.wordpress.com
>>>> Home: http://garygregory.com/
>>>> Tweet! http://twitter.com/GaryGregory
>>>>
>>>
>>>
>>>
>>> --
>>> Matt Sicker <bo...@gmail.com>
>>>
>>>
>>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Ralph Goers <ra...@dslextreme.com>.
I just did this the other day for both XML and JSON.  

For XML I did:

    public static TransactionRequest deserialize(String xmlFile) {
        try {
            XmlMapper mapper = new XmlMapper();
            InputStream stream = new FileInputStream(xmlFile);
            return mapper.readValue(stream, TransactionRequest.class);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
    public static TransactionRequest deserialize(String xmlFile) {
        try {
            XmlMapper mapper = new XmlMapper();
            InputStream stream = new FileInputStream(xmlFile);
            return mapper.readValue(stream, TransactionRequest.class);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

Where needed I used things like:

    @JacksonXmlProperty(localName = "return")
    private PostSale creditCardReturn;

and 

    @JacksonXmlProperty(isAttribute = true)

For JSON I did

    public static JSONRequest deserialize(String json)
    {
        try
        {
            ObjectMapper mapper = new ObjectMapper();
            return mapper.readValue(json, JSONRequest.class);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }

and

    public String serialize()
    {
        try
        {
            final ObjectMapper mapper = new ObjectMapper();
            return mapper.writeValueAsString(this);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }

HTH,

Ralph


On Apr 1, 2014, at 1:05 PM, Gary Gregory <ga...@gmail.com> wrote:

> Well... so much for Jackson making my life easy. Jackson says it "supports" JAXB annotations but that must be only for the simplest cases. Jackson does not work with the JAXB annotations I used on Log4jLogEvents. This suppose this is not surprising. Back to the drawing board...
> 
> Gary
> 
> 
> On Tue, Apr 1, 2014 at 12:05 PM, Gary Gregory <ga...@gmail.com> wrote:
> All good ideas, thank you. The JSON API I know best is GSON, which let's you listen to objects opening and closing. Maybe Jackson has something like that... I'll have to dig in.
> 
> Gary
> 
> 
> On Tue, Apr 1, 2014 at 11:14 AM, Ralph Goers <ra...@dslextreme.com> wrote:
> So you are hacking the stream before passing it to the unmarshalling framework?  Then you will have to keep track of the ‘{‘ and ‘}’ characters yourself, either with the stack Matt suggests or as a counter.
> 
> Ralph
> 
> On Apr 1, 2014, at 8:07 AM, Matt Sicker <bo...@gmail.com> wrote:
> 
>> Keep a stack of {'s and pop them when you get a }. Like a deterministic pushdown automaton.
>> 
>> 
>> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
>> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP socket servers unmarhsal XML log events.
>> 
>> This is "easy" for XML because when you have a stream of bytes and you know its encoding, you can look for the end of an event by looking for its closing tag: </Event>. Right now, my XML processing code, looks for the end tag and feeds JAXB a substring from the buffer. Easy. Done.
>> 
>> Not so much with JSON. You cannot use the same hack, there is no end tag. All you have is an "end of object" closing bracket "}" which looks the same as the closing marker for all other objects.
>> 
>> So it looks like I would need to hook in a little deeper into a JSON unmarshalling framework to extract each JSON log events as I see them.
>> 
>> Any thoughts here?
>> 
>> Gary
>> 
>> -- 
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>> Java Persistence with Hibernate, Second Edition
>> JUnit in Action, Second Edition
>> Spring Batch in Action
>> Blog: http://garygregory.wordpress.com 
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>> 
>> 
>> 
>> -- 
>> Matt Sicker <bo...@gmail.com>
> 
> 
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
> 
> 
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory


Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Gary Gregory <ga...@gmail.com>.
Well... so much for Jackson making my life easy. Jackson says it "supports"
JAXB annotations but that must be only for the simplest cases. Jackson does
not work with the JAXB annotations I used on Log4jLogEvents. This suppose
this is not surprising. Back to the drawing board...

Gary


On Tue, Apr 1, 2014 at 12:05 PM, Gary Gregory <ga...@gmail.com>wrote:

> All good ideas, thank you. The JSON API I know best is GSON, which let's
> you listen to objects opening and closing. Maybe Jackson has something like
> that... I'll have to dig in.
>
> Gary
>
>
> On Tue, Apr 1, 2014 at 11:14 AM, Ralph Goers <ra...@dslextreme.com>wrote:
>
>> So you are hacking the stream before passing it to the unmarshalling
>> framework?  Then you will have to keep track of the ‘{‘ and ‘}’ characters
>> yourself, either with the stack Matt suggests or as a counter.
>>
>> Ralph
>>
>> On Apr 1, 2014, at 8:07 AM, Matt Sicker <bo...@gmail.com> wrote:
>>
>> Keep a stack of {'s and pop them when you get a }. Like a deterministic
>> pushdown automaton.
>>
>>
>> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
>>
>>> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP socket
>>> servers unmarhsal XML log events.
>>>
>>> This is "easy" for XML because when you have a stream of bytes and you
>>> know its encoding, you can look for the end of an event by looking for its
>>> closing tag: </Event>. Right now, my XML processing code, looks for the end
>>> tag and feeds JAXB a substring from the buffer. Easy. Done.
>>>
>>> Not so much with JSON. You cannot use the same hack, there is no end
>>> tag. All you have is an "end of object" closing bracket "}" which looks the
>>> same as the closing marker for all other objects.
>>>
>>> So it looks like I would need to hook in a little deeper into a JSON
>>> unmarshalling framework to extract each JSON log events as I see them.
>>>
>>> Any thoughts here?
>>>
>>> Gary
>>>
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>>> Spring Batch in Action <http://www.manning.com/templier/>
>>> Blog: http://garygregory.wordpress.com
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory
>>>
>>
>>
>>
>> --
>> Matt Sicker <bo...@gmail.com>
>>
>>
>>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Gary Gregory <ga...@gmail.com>.
All good ideas, thank you. The JSON API I know best is GSON, which let's
you listen to objects opening and closing. Maybe Jackson has something like
that... I'll have to dig in.

Gary


On Tue, Apr 1, 2014 at 11:14 AM, Ralph Goers <ra...@dslextreme.com>wrote:

> So you are hacking the stream before passing it to the unmarshalling
> framework?  Then you will have to keep track of the ‘{‘ and ‘}’ characters
> yourself, either with the stack Matt suggests or as a counter.
>
> Ralph
>
> On Apr 1, 2014, at 8:07 AM, Matt Sicker <bo...@gmail.com> wrote:
>
> Keep a stack of {'s and pop them when you get a }. Like a deterministic
> pushdown automaton.
>
>
> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
>
>> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP socket
>> servers unmarhsal XML log events.
>>
>> This is "easy" for XML because when you have a stream of bytes and you
>> know its encoding, you can look for the end of an event by looking for its
>> closing tag: </Event>. Right now, my XML processing code, looks for the end
>> tag and feeds JAXB a substring from the buffer. Easy. Done.
>>
>> Not so much with JSON. You cannot use the same hack, there is no end tag.
>> All you have is an "end of object" closing bracket "}" which looks the same
>> as the closing marker for all other objects.
>>
>> So it looks like I would need to hook in a little deeper into a JSON
>> unmarshalling framework to extract each JSON log events as I see them.
>>
>> Any thoughts here?
>>
>> Gary
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
>> Spring Batch in Action <http://www.manning.com/templier/>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Ralph Goers <ra...@dslextreme.com>.
So you are hacking the stream before passing it to the unmarshalling framework?  Then you will have to keep track of the ‘{‘ and ‘}’ characters yourself, either with the stack Matt suggests or as a counter.

Ralph

On Apr 1, 2014, at 8:07 AM, Matt Sicker <bo...@gmail.com> wrote:

> Keep a stack of {'s and pop them when you get a }. Like a deterministic pushdown automaton.
> 
> 
> On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:
> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP socket servers unmarhsal XML log events.
> 
> This is "easy" for XML because when you have a stream of bytes and you know its encoding, you can look for the end of an event by looking for its closing tag: </Event>. Right now, my XML processing code, looks for the end tag and feeds JAXB a substring from the buffer. Easy. Done.
> 
> Not so much with JSON. You cannot use the same hack, there is no end tag. All you have is an "end of object" closing bracket "}" which looks the same as the closing marker for all other objects.
> 
> So it looks like I would need to hook in a little deeper into a JSON unmarshalling framework to extract each JSON log events as I see them.
> 
> Any thoughts here?
> 
> Gary
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>


Re: LOG4J2-583, XML and JSON unmarshalling

Posted by Matt Sicker <bo...@gmail.com>.
Keep a stack of {'s and pop them when you get a }. Like a deterministic
pushdown automaton.


On 1 April 2014 07:45, Gary Gregory <ga...@gmail.com> wrote:

> I have a local patch for LOG4J2-583 to have the Log4j TCP and UDP socket
> servers unmarhsal XML log events.
>
> This is "easy" for XML because when you have a stream of bytes and you
> know its encoding, you can look for the end of an event by looking for its
> closing tag: </Event>. Right now, my XML processing code, looks for the end
> tag and feeds JAXB a substring from the buffer. Easy. Done.
>
> Not so much with JSON. You cannot use the same hack, there is no end tag.
> All you have is an "end of object" closing bracket "}" which looks the same
> as the closing marker for all other objects.
>
> So it looks like I would need to hook in a little deeper into a JSON
> unmarshalling framework to extract each JSON log events as I see them.
>
> Any thoughts here?
>
> Gary
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
Matt Sicker <bo...@gmail.com>