Skip to content

Commit

Permalink
Drop valueToNode method
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-krecan committed Jul 17, 2024
1 parent 0ee277f commit a52c6a9
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ public Node convertToNode(Object source, String label, boolean lenient) {
}
}

@Override
public Node valueToNode(Object source) {
if (source == null) {
return nullNode();
} else {
return convertValue(source);
}
}

final Node convertValue(Object source) {
if (source instanceof BigDecimal) {
return new GenericNodeBuilder.NumberNode((Number) source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@ Node convertToNode(@Nullable Object source, String label, boolean lenient) {
return findBestFactory(source).convertToNode(source, label, lenient);
}

@NotNull
Node valueToNode(Object source) {
return findBestFactory(source).valueToNode(source);
}

private NodeFactory findBestFactory(Object source) {
if (factories.size() == 1) return factories.get(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,6 @@ public static Node convertToJson(@Nullable Object source, String label, boolean
}
}

/**
* Converts value to Json node. It can be Map, String, null, or primitive. Should not be parsed, just converted.
*/
@NotNull
public static Node valueToNode(Object source) {
if (source instanceof Node) {
return (Node) source;
} else {
return converter.valueToNode(source);
}
}

/**
* Returns node with given path.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,4 @@ interface NodeFactory {
* @return
*/
Node convertToNode(@Nullable Object source, String label, boolean lenient);

/**
* Converts value to Json node. It can be Map, String, null, or primitive. Should not be parsed, just converted.
*
* @param source
* @return
*/
Node valueToNode(Object source);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
*/
package net.javacrumbs.jsonunit.core.internal;

import static java.util.Collections.singletonMap;
import static net.javacrumbs.jsonunit.core.internal.JsonUtils.convertToJson;
import static net.javacrumbs.jsonunit.core.internal.JsonUtils.getNode;
import static net.javacrumbs.jsonunit.core.internal.JsonUtils.nodeAbsent;
import static net.javacrumbs.jsonunit.core.internal.JsonUtils.quoteIfNeeded;
import static net.javacrumbs.jsonunit.core.internal.JsonUtils.valueToNode;
import static net.javacrumbs.jsonunit.core.internal.Node.NodeType.ARRAY;
import static net.javacrumbs.jsonunit.core.internal.Node.NodeType.BOOLEAN;
import static net.javacrumbs.jsonunit.core.internal.Node.NodeType.NULL;
import static net.javacrumbs.jsonunit.core.internal.Node.NodeType.NUMBER;
import static net.javacrumbs.jsonunit.core.internal.Node.NodeType.OBJECT;
import static net.javacrumbs.jsonunit.core.internal.Node.NodeType.STRING;
Expand All @@ -33,7 +30,6 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.math.BigDecimal;
import org.junit.jupiter.api.Test;

class JsonUtilsTest {
Expand All @@ -57,23 +53,6 @@ void testConvertToJson() {
assertTrue(convertToJson(null, "x").isNull());
}

@Test
void testValueToJson() {
assertEquals(STRING, valueToNode("a").getNodeType());
assertEquals(NUMBER, valueToNode(BigDecimal.valueOf(1)).getNodeType());
assertEquals(STRING, valueToNode("1").getNodeType());
assertEquals(NUMBER, valueToNode(1.0).getNodeType());
assertEquals(STRING, valueToNode("1.0").getNodeType());
assertEquals(OBJECT, valueToNode(singletonMap("a", 1)).getNodeType());
assertEquals(ARRAY, valueToNode(new int[] {1, 2, 3}).getNodeType());
assertEquals(STRING, valueToNode("true").getNodeType());
assertEquals(BOOLEAN, valueToNode(true).getNodeType());
assertEquals(STRING, valueToNode("false").getNodeType());
assertEquals(BOOLEAN, valueToNode(false).getNodeType());
assertEquals(STRING, valueToNode("null").getNodeType());
assertEquals(NULL, valueToNode(null).getNodeType());
}

@Test
void testQuoteIfNeeded() {
assertEquals("1", quoteIfNeeded("1"));
Expand Down

0 comments on commit a52c6a9

Please sign in to comment.