[jira] [Commented] (FELIX-5678) Allow merging of objects
[ https://issues.apache.org/jira/browse/FELIX-5678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16128952#comment-16128952 ] David Bosschaert commented on FELIX-5678: - Hi [~dleangen], so you really want to convert two objects into one :) While the converter API isn't really designed for this, you could achieve it with a custom rule, where the rule is specifically created for this conversion with the second object as context provided to the rule, i.e. {code} Foo f = ...; ConverterBuilder builder = converter.newConverterBuilder(); builder.rule(new TypeRule<>(Map.class, Foo.class, {v -> merge(f, v)}); Converter c = builder.build(); Foo f2 = c.convert(m).to(Foo.class); // f is already passed to the rule {code} Maybe not the most elegant, but it might work? > Allow merging of objects > > > Key: FELIX-5678 > URL: https://issues.apache.org/jira/browse/FELIX-5678 > Project: Felix > Issue Type: Bug > Components: Converter >Reporter: David Leangen > > 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 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 (v6.4.14#64029)
[jira] [Commented] (FELIX-5678) Allow merging of objects
[ https://issues.apache.org/jira/browse/FELIX-5678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16169637#comment-16169637 ] David Leangen commented on FELIX-5678: -- Hi [~bosschaert], thank you for your reply! I got sidetracked, but am finally turning my attention back to this. :-) bq. so you really want to convert two objects into one That is a good question, and I suppose that it depends on the level of abstraction. From a conceptual level, I think the intent is to update an object. For instance (just an example I am pulling out of my ear), say I have a Customer object, and I notice that the last name is spelled incorrectly. All I want to do is correct that part, so the system somehow receives a message with the ID of the customer to update, and the portions of the records that need to be updated. There is no point sending along the entire record if I only want to change an "i" to an "e" in one single field! However, from the converter/data level, I suppose you are right: it is really just merging two objects. (Or is it?? Not sure yet.) I was also starting to think that maybe a [diff format|http://wiki.c2.com/?DiffAlgorithm] would work well. Each field, instead of containing an actual value, would contain only a diff value. bq. While the converter API isn't really designed for this, you could achieve it with a custom rule, where the rule is specifically created for this conversion with the second object as context provided to the rule Possible, yes. And IIUC the API is no longer open for comments, correct? So either we'd have to go about it this way, or build an extra layer on top of the Converter. Or, maybe this is something all together different. wdyt? > Allow merging of objects > > > Key: FELIX-5678 > URL: https://issues.apache.org/jira/browse/FELIX-5678 > Project: Felix > Issue Type: Bug > Components: Converter >Reporter: David Leangen > > 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 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 (v6.4.14#64029)
[jira] [Commented] (FELIX-5678) Allow merging of objects
[ https://issues.apache.org/jira/browse/FELIX-5678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16172958#comment-16172958 ] David Bosschaert commented on FELIX-5678: - bq. IIUC the API is no longer open for comments, correct? So either we'd have to go about it this way, or build an extra layer on top of the Converter. Or, maybe this is something all together different. Yes, the OSGi Converter API for the R7 release is pretty much locked down now, but we can still work on enhancements and improvements for R8... > Allow merging of objects > > > Key: FELIX-5678 > URL: https://issues.apache.org/jira/browse/FELIX-5678 > Project: Felix > Issue Type: Bug > Components: Converter >Reporter: David Leangen > > 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 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 (v6.4.14#64029)
[jira] [Commented] (FELIX-5678) Allow merging of objects
[ https://issues.apache.org/jira/browse/FELIX-5678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16586640#comment-16586640 ] David Leangen commented on FELIX-5678: -- Hi [~bosschaert], long time no chat. Could this type of feature be added as a Felix extension, or should I close the issue? > Allow merging of objects > > > Key: FELIX-5678 > URL: https://issues.apache.org/jira/browse/FELIX-5678 > Project: Felix > Issue Type: Bug > Components: Converter >Reporter: 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 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)
[jira] [Commented] (FELIX-5678) Allow merging of objects
[ https://issues.apache.org/jira/browse/FELIX-5678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16851531#comment-16851531 ] David Leangen commented on FELIX-5678: -- Hi [~bosschaert], Very long time no see. :) I wanted to get back to this issue. I am now coming across the need to merge (patch) objects. Given the current state of the project, what do you think would be the best way forward at this time? Thanks! > Allow merging of objects > > > Key: FELIX-5678 > URL: https://issues.apache.org/jira/browse/FELIX-5678 > Project: Felix > Issue Type: Bug > Components: Converter >Reporter: 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 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)
[jira] [Commented] (FELIX-5678) Allow merging of objects
[ https://issues.apache.org/jira/browse/FELIX-5678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16851706#comment-16851706 ] David Bosschaert commented on FELIX-5678: - Hi [~dleangen], I think the simplest solution would be to take your 2 objects and convert them both to simple Maps using the converter. Then you can merge the 2 maps by calling {{map1.putAll(map2)}} Finally you can convert your resulting map back to the target object you need using the converter. Alternatively you should be able to use a custom converter rule like described in the first comment, and in more detail here: [https://osgi.org/specification/osgi.enterprise/7.0.0/util.converter.html#util.converter-customizing.converters] Let me know if this helps... Cheers, David > Allow merging of objects > > > Key: FELIX-5678 > URL: https://issues.apache.org/jira/browse/FELIX-5678 > Project: Felix > Issue Type: Bug > Components: Converter >Reporter: 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 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)
[jira] [Commented] (FELIX-5678) Allow merging of objects
[ https://issues.apache.org/jira/browse/FELIX-5678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16852320#comment-16852320 ] David Leangen commented on FELIX-5678: -- Thanks, [~bosschaert]. I get that. I have no problem technically making a customisation for my own code, but this is an operation that is wide ranging and fundamental, IMO. It would be nice to have a way to do this on the platform level. Is there any possibility of proposing this for R8? In the meantime, is there any way of extending or branding the current release? This type of operation could be thought of as being analogous to http patch. (Maybe it should even be called "patch" instead of "merge".) For people like me who use DTOs extensively as a fundamental building block, it is a frequently-used operation. Also it would be much more efficient to do it as a "native" operation of the converter rather than having to do multiple conversions. Any thoughts? Or is it too early to be discussing R8 and extensions? > Allow merging of objects > > > Key: FELIX-5678 > URL: https://issues.apache.org/jira/browse/FELIX-5678 > Project: Felix > Issue Type: Bug > Components: Converter >Reporter: 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 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)
[jira] [Commented] (FELIX-5678) Allow merging of objects
[ https://issues.apache.org/jira/browse/FELIX-5678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16852604#comment-16852604 ] David Leangen commented on FELIX-5678: -- Just to update the information here with two discoveries as I continue to investigate... Although perhaps frequently required, the number of "places" in the code where the patch operation is required is probably limited, mostly to the lower-level data layer. This would be an argument against having a patch operation in the Converter. An argument for, though, is that a patch may be "deep". This turns out to be non-trivial (i.e. more complex than just putAll as you suggest), as there is a need to iterate deep into the object. This traversal is already being done internally by the Converter, so it may provide a great opportunity to perform this operation from inside the Converter. > Allow merging of objects > > > Key: FELIX-5678 > URL: https://issues.apache.org/jira/browse/FELIX-5678 > Project: Felix > Issue Type: Bug > Components: Converter >Reporter: 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 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)
[jira] [Commented] (FELIX-5678) Allow merging of objects
[ https://issues.apache.org/jira/browse/FELIX-5678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16852851#comment-16852851 ] David Bosschaert commented on FELIX-5678: - Hi [~dleangen] somehow I think that a merger is fundamentally different to a converter, albeit the case that it may be easy to implement a deep merger with the help of the converter. So to me it sounds like a separate component. I have to admit, I have not really had the need for a deep merger myself that often, but that doesn't mean others don't need it. I would suggest discussing it on one of the Felix mailing lists (for increased visibility) and maybe get an initial implementation started in Felix? Maybe we can take it from there? Oh, and BTW it's certainly not too early for OSGi R8 proposals :) > Allow merging of objects > > > Key: FELIX-5678 > URL: https://issues.apache.org/jira/browse/FELIX-5678 > Project: Felix > Issue Type: Bug > Components: Converter >Reporter: 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 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)
[jira] [Commented] (FELIX-5678) Allow merging of objects
[ https://issues.apache.org/jira/browse/FELIX-5678?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16853473#comment-16853473 ] David Leangen commented on FELIX-5678: -- Hey [~bosschaert], Hmmm, you may be right. It could be because I am using the Converter for something much greater than what it was intended to be. It is, in my framework, a central integration tool, allowing the front-end to work seamlessly with the back end and data tiers, since all data is communicated via DTOs == JSON. It turns out that, thanks to the Converter, this kind of full-stack integration has a beautiful simplicity to it. No ORM etc. required, just the plain old Converter. I would have thought that everybody does this, which is why this functionality makes sense to me. If I am alone, then indeed it would likely be out-of-scope of the original intention. I'll have to give this some thought and get back to you. Perhaps what I need is a higher level of abstraction based on the Converter. Then again, but for the patch operation, the abstraction would probably be identical! I'll put this on hold again for now. I'll first build what I need outside of the Converter as you suggest, then decide whether or not it's worth trying to integrate with the Converter, and how. After prototyping, I'll consider making a proposal on the Felix list. Perhaps a paper to explain what I'm doing would be in order as well. Thanks, as always, for your comments. > Allow merging of objects > > > Key: FELIX-5678 > URL: https://issues.apache.org/jira/browse/FELIX-5678 > Project: Felix > Issue Type: Bug > Components: Converter >Reporter: 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 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)
[jira] [Commented] (FELIX-5678) Allow merging of objects
[ 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 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)