Skip to content

Commit

Permalink
renames
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddenton committed Jan 5, 2024
1 parent 4b8dd13 commit 6cf5a2b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ import java.math.BigDecimal
/**
* Jackson JsonNode-based implementation of the DataContainer
*/
abstract class JacksonDataContainer(input: JsonNode) :
abstract class JsonNodeDataContainer(input: JsonNode) :
DataContainer<JsonNode>(
input,
{ content, it -> content.has(it) },
{ content, it -> content[it]?.let(Companion::nodeToValue) },
{ node: JsonNode, name, value ->
(node as? ObjectNode)?.also {
node.set<JsonNode>(name, value.toNode())
} ?: error("Invalid node type ${input::class.java}")
(node as? ObjectNode)?.also { node.set<JsonNode>(name, value.toNode()) }
?: error("Invalid node type ${input::class.java}")
}
) {

Expand Down Expand Up @@ -58,9 +57,10 @@ abstract class JacksonDataContainer(input: JsonNode) :
is BigDecimal -> DecimalNode(this)
is Double -> DoubleNode(this)
is String -> TextNode(this)
is Iterable<*> -> ArrayNode(instance).also {
map { if (it is JsonNode) it else it.toNode() }.forEach(it::add)
is Iterable<*> -> ArrayNode(instance)
.also { map { if (it is JsonNode) it else it.toNode() }.forEach(it::add)
}

else -> error("Cannot set value of type ${this::class.java}")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package dev.forkhandles.lens

import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import dev.forkhandles.data.JacksonDataContainer
import dev.forkhandles.data.JsonNodeDataContainer
import java.math.BigDecimal

class JacksonDataContainerTest : DataContainerContract<JacksonDataContainerTest.SubNodeBacked>() {
class JsonNodeDataContainerTest : DataContainerContract<JsonNodeDataContainerTest.SubNodeBacked>() {

class SubNodeBacked(node: JsonNode) : JacksonDataContainer(node), SubClassFields {
class SubNodeBacked(node: JsonNode) : JsonNodeDataContainer(node), SubClassFields {
override var string by required<String>()
override var noSuch by required<String>()
}

class NodeBacked(node: JsonNode) : JacksonDataContainer(node), MainClassFields<SubNodeBacked> {
class NodeBacked(node: JsonNode) : JsonNodeDataContainer(node), MainClassFields<SubNodeBacked> {
override var string by required<String>()
override var boolean by required<Boolean>()
override var int by required<Int>()
Expand Down

0 comments on commit 6cf5a2b

Please sign in to comment.