Created
September 4, 2019 20:31
-
-
Save pbatey/c8381d3b1e529c5a611a84909c8733ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.databind.ObjectMapper; | |
import org.junit.Test; | |
import java.io.IOException; | |
import java.util.Map; | |
import static org.junit.Assert.*; | |
public class FlattenerTest { | |
@Test | |
public void testitShouldFlatten() throws IOException { | |
String json = "{\"root\":{\"shallowValue\":0,\"deep\":{\"deepValue\":0,\"array\":[1,2,3]},\"array\":[4,5,6,7]}}"; | |
ObjectMapper mapper = new ObjectMapper(); | |
Map<String, Object> map = mapper.readValue(json, Map.class); | |
Flattener.process(map); | |
String result = mapper.writeValueAsString(map); | |
assertEquals("{\"root_shallowValue\":0,\"root_deep_array_count\":3,\"root_array_count\":4,\"root_deep_deepValue\":0}", result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unit Test for https://gist.github.com/pbatey/4113ca593c181c94bc9c9f98972abe56