Delete record path
Hi,
How can i delete a field in a record ?
{
fieldToClean: {
fieldA: '..',
fieldB: '..',
fieldC: '..'
}
}
How can i with java client delete fieldB (not setting null)
Hey @pgoergler, the deepstream protocol deletes properties in records when it receives undefined. This is great in JavaScript but not so much in Java, where there is no concept of undefined.
The workaround using the java client would be something like the following:
Record record = client.record.getRecord('...');
JsonObject json = record.get();
System.out.println(json);
// {
// fieldToClean: {
// fieldA: '..',
// fieldB: '..',
// fieldC: '..'
// }
// }
JsonObject nestedJson = json.get('fieldToClean');
nestedJson.remove('fieldB');
record.set(json);
There needs to be some casting, and you may need to set the fieldToClean property of the json object, but this would remove the property fieldB.
Ok i understand, is it planed to simplify this process ? Maybe by adding a JsonUndefined object which let us write something like
Record record = client.record.getRecord('...');
record.set('fieldToClean.fieldB', new JsonUndefined());
Happy for some discussion around this, that would work but feels weird as an api.
Something like
record.delete('path.nestedPath')
feels more natural, but goes against the api people are familiar with.
Would be interested to see what members of the community think about this.
And what about :
record.unset('path.nestedPath');