Skip to content

Instantly share code, notes, and snippets.

@pbatey
Created September 4, 2019 20:31
Show Gist options
  • Save pbatey/c8381d3b1e529c5a611a84909c8733ee to your computer and use it in GitHub Desktop.
Save pbatey/c8381d3b1e529c5a611a84909c8733ee to your computer and use it in GitHub Desktop.
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);
}
}
@pbatey
Copy link
Author

pbatey commented Sep 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment