io.sphere.sdk.customobjects.commands.CustomObjectCustomJsonMappingUpsertCommand Maven / Gradle / Ivy
package io.sphere.sdk.customobjects.commands;
import io.sphere.sdk.client.HttpRequestIntent;
import io.sphere.sdk.commands.CreateCommand;
import io.sphere.sdk.customobjects.CustomObject;
import io.sphere.sdk.client.SphereRequestBase;
import io.sphere.sdk.http.HttpMethod;
import io.sphere.sdk.http.HttpResponse;
/**
Command for creating or updating a custom object using a custom JSON mapper.
Example using Google GSON (multiple code snippets):
The execution of the command:
{@include.example io.sphere.sdk.customobjects.commands.CustomObjectCustomJsonMappingUpsertCommandTest#execution()}
The command class:
{@include.example io.sphere.sdk.customobjects.demo.GsonFooCustomObjectUpsertCommand}
The draft containing container, key and value:
{@include.example io.sphere.sdk.customobjects.demo.GsonFooCustomObjectDraft}
The resulting custom object class:
{@include.example io.sphere.sdk.customobjects.demo.GsonFooCustomObject}
The class of the value:
{@include.example io.sphere.sdk.customobjects.demo.GsonFoo}
@param The type of the value of this custom object.
@see CustomObject
*/
public abstract class CustomObjectCustomJsonMappingUpsertCommand extends SphereRequestBase implements CreateCommand> {
@Override
public abstract CustomObject deserialize(final HttpResponse httpResponse);
@Override
public final HttpRequestIntent httpRequestIntent() {
return HttpRequestIntent.of(HttpMethod.POST, "/custom-objects", bodyAsJsonString());
}
/**
* Produces JSON to create or update a custom object.
* It must have the fields of a {@link io.sphere.sdk.customobjects.CustomObject}:
*
* Example:
*
* {@code
{
"container": "myNamespace",
"key": "myKey",
"value": {
"baz": 3,
"bar": "a String"
}
}
* }
*
* @return JSON as String
*/
protected abstract String bodyAsJsonString();
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy