Danke für die Antwort und den Link,
das hatte ich auch schon angeschaut ist aber nicht das richtige
für mein Problem.
Ich möchte eigentlich einfach zwei JSON Strings / Files / Objekte egal
in welcher Form zu einem Ergebniss d.h. einem JSON irgendwas zusammen-
fügen, dabei ist es mir relativ egal wie das vonstatten gehen kann ich habe es mit
Java versucht mit Rekursion aber bekomme das nicht hin.
Solange nur Maps und Strings da sind (im JSON) geht das aber die Arrays bzw.
Listen dadrin bekomme ich nicht vernünftig abgeglichen.
Evtl hab ich auch nur einen gedanklichen Hänger und brauche nur einen Anstoss in die richtige Richtung
Das hier ist mein Ansatz gewesen aber ich steh auf dem Schlauch ;(
Code:
public void compare(String key, Object object){
if(object instanceof Map<?,?>){
Map<String, Object> newObject = (Map<String, Object>) object;
Depth tiefe = new Depth(key, 'M');
depth.add(tiefe);
this.compareMap(newObject);
}
else if(object instanceof ArrayList<?>){
ArrayList<Object> newObject = (ArrayList<Object>) object;
Depth tiefe = new Depth(key, 'A');
depth.add(tiefe);
this.compareArrayList(newObject);
}
else if(object instanceof String){
String newObject = (String) object;
this.compareString(newObject);
}
}
public void compareMap(Map<String, Object> map){
for (Map.Entry<String, Object> entry : map.entrySet()){
compare(entry.getKey(), entry.getValue());
}
}
public void compareArrayList(ArrayList<Object> array){
Iterator<Object> listIterator = array.iterator();
while(listIterator.hasNext()){
compare("ARRAY", listIterator.next());
}
}
public void compareString(String string){
Object container = resultMap;
Iterator<Depth> depthIterator = depth.iterator();
while(depthIterator.hasNext()){
Depth actuallDepth = depthIterator.next();
if(container instanceof Map<?,?>){
Map<String,Object> realContainer = (Map<String,Object>)container;
if(!(realContainer.containsKey(actuallDepth.getKey()) && actuallDepth.getKey() == "ARRAY")){
if(actuallDepth.getType() == 'M'){
Map<String, Object> newMap = new HashMap<String, Object>();
realContainer.put(actuallDepth.getKey(), newMap);
container = newMap;
}
else if(actuallDepth.getType() == 'A'){
ArrayList<Object> newArray = new ArrayList<Object>();
realContainer.put(actuallDepth.getKey(), newArray);
container = newArray;
}
}
}
else if(container instanceof ArrayList<?>){
ArrayList<Object> realContainer = (ArrayList<Object>)container;
if(realContainer.){
}
}
} // end of while
} // end of method compareString