Interface ContractStateVaultJsonFactory
-
- All Implemented Interfaces:
public interface ContractStateVaultJsonFactory<T extends ContractState>
Implement a ContractStateVaultJsonFactory to create a JSON representation of a state to store alongside the state in the vault. This JSON representation can be used to query states from flows using query.
Classes that implement ContractStateVaultJsonFactory will be executed in a hierarchical way. That means every factory that belongs to a given state or that given state's ancestors will be executed and the end result will be a combined JSON. The combined JSON will be keyed by the state type specified by the factory.
In order to perform a "query by state" query using `UtxoLedgerService.query` for a particular state type, a factory for that given type must be present, even if it's just returning an empty JSON string.
Please note that only one factory can be registered for a state type.
Example usage:
- Kotlin:
class TestUtxoStateVaultJsonFactory: ContractStateVaultJsonFactory<TestUtxoState> { private data class TestUtxoStatePojo(val testField: String) override val stateType: Class<TestUtxoState> = TestUtxoState::class.java override fun append(state: TestUtxoState, jsonMarshallingService: JsonMarshallingService): String { return jsonMarshallingService.format(TestUtxoStatePojo(state.testField)) } }
- Java:
public class TestUtxoStateVaultJsonFactory implements ContractStateVaultJsonFactory<TestUtxoState> { private class TestUtxoStatePojo { private String testField; TestUtxoStatePojo(String testField) { this.testField = testField; } String getTestField() { return this.testField; } } public Class<T> getStateType() { return TestUtxoState.class; } public String append(TestUtxoState state, JsonMarshallingService jsonMarshallingService) { return jsonMarshallingService.format(new TestUtxoStatePojo(state.getTestField())); } }
-
-
Method Summary
Modifier and Type Method Description abstract Class<T>
getStateType()
abstract String
create(@NotNull() T state, @NotNull() JsonMarshallingService jsonMarshallingService)
The function that defines how the given state can be represented as a JSON string. -
-
Method Detail
-
getStateType
@NotNull() abstract Class<T> getStateType()
-
create
@NotNull() abstract String create(@NotNull() T state, @NotNull() JsonMarshallingService jsonMarshallingService)
The function that defines how the given state can be represented as a JSON string.
- Parameters:
state
- The state object.jsonMarshallingService
- An instance of a JsonMarshallingService that can be used when creating a JSON representation.
-
-
-
-