Corda’s handling of Mutable Containers

  1. Query for the input state
  2. Create the output state by using .copy method on input state
  3. Now I change stuff in this new output state depending on the flow (e.g. Changing the status from “REQUESTED” to “ACCEPTED”.. etc)
  4. In the new output state, I wanted to add another attribute to the map, so I fetched the map from this object and called the “put” method to add a new entry into the map.
  5. Build, sign, share the transaction.
[WARN ] [Node thread-1] flow.[ea6df23d-b3a9–423f-a5b9-b45a15640088].run - Terminated by unexpected exception {}
java.lang.UnsupportedOperationException: null
at java.util.Collections$UnmodifiableCollection.addAll(Unknown Source) ~[?:1.8.0_161]
……….
/// LONG STACK TRACE …..
data class Foo(val l : MutableList<String>)// Corda internally runs the two statements below when you save to ledger and read back from itval bytes = Foo(mutableListOf ("a", "b", "c")).serialize()val newFoo = bytes.deserialize()newFoo.l.add("d")  // UnsupportedOperationException
  1. If using a data class, you can provide a “@ConstructorForDeserialization” annotation to tell Corda how to deserialize this object.
data class Foo(val l : MutableList<String>){@ConstructorForDeserialization@Suppress("Unused")constructor (l : Collection<String>) : this (l.toMutableList())}
data class Foo(val l : List<String>)// Corda internally runs the two statements below when you save to ledger and read back from itval bytes = Foo(listOf ("a", "b", "c")).serialize()val newFoo = bytes.deserialize()val newFoo = newFoo.copy (l = (newFoo.l + "d"))
data class Foo(val l : MutableList<String>)// Corda internally runs the two statements below when you save to ledger and read back from itval bytes = Foo(mutableListOf ("a", "b", "c")).serialize()val newFoo = bytes.deserialize()newFoo.l = newFoo.l.toMutableList()newFoo.l.add("d")  // Works

--

--

--

Building the future, one BLOCK at a time. Blockchain R&D engineer @PersistentSys.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Wen Mint? Reviews: Glizzy Gang CNFT

Who Is Technical Writer?

Enable WSO2 Log Viewer

Would you hire a junior Linux admin with these skills — Part 2

How To Make a Button with a Gradient Border and Gradient Text in HTML & CSS

Highlights from the TrailheaDX ’21 Main Show: Watch at Home Guide

Photo of a wooden sign saying Welcome to TrailheaDX. An Astro statue stands next to it surrounded by greenery and rocks.

OpenShift IPI Install: Failed to get power state for node. Error: Redfish exception occurred.

THESE RESOURCES SIMPLIFY FRONT-END DEVELOPMENT

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amol Pednekar

Amol Pednekar

Building the future, one BLOCK at a time. Blockchain R&D engineer @PersistentSys.

More from Medium

viewmodelscope.launch scope running on the main thread | Flow | Repository

Dependency Injection | Much Easier now… :)

Classifying categorical data in Weka via the API

Learn Kotlin -Null Safety