
com.tananaev.jsonpatch.operation.RemoveOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-patch Show documentation
Show all versions of json-patch Show documentation
A Gson-based JSON patch standard implementation.
The newest version!
package com.tananaev.jsonpatch.operation;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.tananaev.jsonpatch.JsonPath;
public class RemoveOperation extends AbsOperation{
public RemoveOperation( JsonPath path ) {
this.path = path;
}
@Override
public String getOperationName() {
return "remove";
}
@Override
public void applyInPlace(InPlaceElementWrapper inPlaceElement) {
JsonElement item = path.head().navigate(inPlaceElement.getJsonElement());
if ( item.isJsonObject() ){
item.getAsJsonObject().remove(path.tail());
} else if ( item.isJsonArray() ){
JsonArray array = item.getAsJsonArray();
int index = (path.tail().equals("-")) ? array.size() : Integer.valueOf(path.tail());
array.remove(index);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy