[ 
https://issues.apache.org/jira/browse/FELIX-5666?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16110285#comment-16110285
 ] 

David Leangen commented on FELIX-5666:
--------------------------------------

Hi David B.,

I have been digging around in the code some more to try to understand what is 
happening. I added another test. Since the tests fail, I have @Ingored them.

In order to deserialise an object, since it does not seem to work just doing it 
“directly”, I have been first converting it to a Map. However, this has a few 
issues in some cases.

When there is an embedded object, even if I do “sourceAsDTO”, this information 
gets lost during the serialisation. It happens in this method in 
JsonSerializingImpl:

{code}
    private String encode(Object obj)
{code}


Even though I converted it to a Map, because of the backing Facade, it is not 
true for the test;

{code}
 if (obj instanceof Map).
{code}

However, it is not a DTO, and the “sourceAsDTO” information is not there, so it 
falls through to the bottom and hits this line:

{code}
        return "\"" + converter.convert(obj).to(String.class) + "\"";
{code}


The Serializing class has a with(Converter) method, but the Converter does not 
have a “sourceAsDTO” method I can use in this with(Converter) method. It would 
be too unwieldy to have to inject a rule for every single type of “DTO-like” 
class I wish to deserialise...

I’m a bit stuck figuring out how to deserialise! :-)


Any ideas what we could do? At least for this case, it could be solved by 
somehow maintaining the "sourceAsDTO" information, I think.

By the way, I like the changes to the code. I find that it is much easier to 
follow and understand. Thanks for all your hard work!! :-)

> Serializer goes into infinite loop
> ----------------------------------
>
>                 Key: FELIX-5666
>                 URL: https://issues.apache.org/jira/browse/FELIX-5666
>             Project: Felix
>          Issue Type: Bug
>          Components: Converter
>            Reporter: David Leangen
>
> I'm only guessing as to what the problem is, following some stepping through 
> the code. I could not find any similar existing test cases, but if the 
> following does not immediately click for [~bosschaert], I will try to add one.
> It appears that, when serializing an object to a "DTO-Type" object to a Map, 
> some kind of backing object is created.
> If the backing object contains a field that instantiates the same DTO, then 
> the loop gets created.
> Example:
> {code}
> public class MyDtoType {
>   public String id;
>   public MyDtoType( String anID ) {
>     id = anID;
>   }
>   public static MyDtoType error() {
>     return new MyDtoType( "ERROR" );
>   }
> }
> {code}
> It looks like the serializer keeps calling the error() method infinitely, but 
> I am not able to easily pinpoint where this happens.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to