question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

merge method for JsonObject

See original GitHub issue
What about new method(s) merge for JsonObject... it would be something
simmilar to JsonArray.addAll

void    merge(JsonObject value) 
void    merge(Object value) 

Original issue reported on code.google.com by adamchuk on 20 Oct 2009 at 3:47

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:10

github_iconTop GitHub Comments

3reactions
anshunjaincommented, Dec 5, 2017

plus one to Sebas’ suggestion ! to do a deep copy is non-trivial and more scope for bugs. the strategies suggested could handle this, and one could always plug-in their own strategy

3reactions
GoogleCodeExportercommented, Mar 19, 2015
Hello,

I know it's an old issue to discuss, but I still believe it could be a fine 
feature to have. 
I'm thinking something about this:

new 
GsonMerger().setConflictResolutionStrategy(myResolutionStrategy).merge(jsonObjec
t1, jsonObject2).build();

new 
GsonMerger().setConflictResolutionStrategy(myResolutionStrategy).merge(jsonObjec
t1).merge(jsonObject2).build();

where 

interface ConflictResolutionStrategy {
      void handleError(JsonElement parent, JsonElement oldElement, JsonElement newElement);
}

Following limpbizkit's comment, available options could be:

DefaultConflictResolutionStrategy - throws IllegalArgumentException if name 
conflict [DEFAULT]
AppendElementConflictResolutionStrategy - appends it to the same "bucket"
NonNullElementConflictResolutionStrategy - replaces the previous element only 
if null
NewerElementConflictResolutionStrategy - always replaces the previous element

Why do I refloat this? Because all the examples I saw they were with shallow 
json trees, just one depth-level. It comes a little bit more complex with 
greater json graphs. A single-line utility would be perfect.

Thanks,

Sebas.-

Original comment by scotti.s...@gmail.com on 11 Sep 2014 at 3:01

Read more comments on GitHub >

github_iconTop Results From Across the Web

Merge (Concat) Multiple JSONObjects in Java - Stack Overflow
A ready method to merge any number of JSONObjects: /** * Merges given JSONObjects. Values for identical key names are merged * if...
Read more >
JSON.simple - Merging Objects - Tutorialspoint
JSON.simple - Merging Objects, In JSON.simple, we can merge two JSON Objects easily using JSONObject.putAll() method.
Read more >
How to Merge/Concat Multiple JSONObjects in ... - Crunchify
In Java - What is the best way to combine / merge multiple JSONObjects? JSONObject is an unordered collection of name/value pairs and...
Read more >
net.minidev.json.JSONObject.merge java code examples
How to use. merge. method. in. net.minidev.json.JSONObject · Best Java code snippets using net.minidev.json.JSONObject.merge (Showing top 12 results out of 315).
Read more >
Merge JSON Objects in Java - YouTube
MergeJSONObjects #JavaMergeJSONObjects #JSONObjectsJavaLike, Share, And Subscribe | Professor Saad YousufWatch Our All Videos On This ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found