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

David Leangen commented on FELIX-5678:
--------------------------------------

I have created a personal prototype (not appropriate for sharing at this time) 
to give me a better understanding.

My findings are:
 * the "patch" functionality is not widely used within the system, it is, at 
least in my case, a fairly low-level operation, albeit an important one
 * the operation is actually much more complex than I initially realized, so it 
can not be handled by simply merging maps, as suggested in the comments above
 * there are already people who have thought about this problem: (see JSON 
Patch: [RFC 6902|https://tools.ietf.org/html/rfc6902])
 * there are implementations of JSON Patch available for the front end and for 
the back end
 * javax.json has a JsonPatch implementation

So the problem is solvable, as indeed the prototype shows, and JSON Patch is a 
great candidate for the solution.

However...

Due to the way JsonPatch works, it is not compatible with the Converter. This 
means that the only reasonable way to get the two to work together is by 
serializing a DTO as a JSON String, using a parser to create a JsonObject, 
using JsonPatch to create an updated JsonObject, serializing that object to 
String, then deserializing the JSON back to a DTO. This is very inefficient!!

Given that a DTO is a Java representation of an object and is intended to make 
it easy to convert to/from JSON, it is unfortunate that this inefficiency has 
to occur.

The debate is: is patching out of scope of the Converter or not? It it is 
related, how should the API be updated? If it is not related, how should the 
problem be solved?

I will put this on the back burner for now and attempt to answer this question 
at a later time, hopefully in a few weeks.

> Allow merging of objects
> ------------------------
>
>                 Key: FELIX-5678
>                 URL: https://issues.apache.org/jira/browse/FELIX-5678
>             Project: Felix
>          Issue Type: New Feature
>          Components: Converter
>            Reporter: David Leangen
>            Assignee: David Leangen
>            Priority: Major
>
> Given a typed object O1 and a "partial" representation of an object O2 (for 
> instance in the form of a Map), allow O2 to be merged into O1.
> Example:
> {code}
> public class Foo {
>   public String a;
>   public String b;
>   public String c;
> }
> Foo f = new Foo();
> a = "Eh!";
> b = "Be cool.";
> c = "See you later?";
> Map<String, String> m = new Map<>();
> m.put("b", "Be there or be square");
> Foo f2 = Converter.convert(f).merge(m);
> {code}
> I am sure there are many ways to skin this cat.
> If the Converter API cannot be changed, what would be the best way to tackle 
> this problem?
> (In the meantime, while awaiting comments form [~bosschaert], I'll try to run 
> a few experiments to see if I can come up with something reasonable.)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to