Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 8th, 2012  |  syntax: Java  |  size: 0.77 KB  |  views: 460  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class Test {
  2.         /**
  3.          * I want array be ignored, only taking into account keys
  4.          */
  5.         private static String JSON = "{\"property\":{\"key1\": {}, \"key2\": {}, \"array\":[1, 2]}}";
  6.        
  7.         @JsonIgnoreProperties(ignoreUnknown = true)
  8.         private static class MyBean {
  9.                 private Map<String, Map<String, String>> property;
  10.  
  11.                
  12.                 public Map<String, Map<String, String>> getProperty() {
  13.                         return property;
  14.                 }
  15.  
  16.                 public void setProperty(Map<String, Map<String, String>> property) {
  17.                         this.property = property;
  18.                 }
  19.         }
  20.        
  21.         public static void main(String[] args) throws IOException {
  22.                 ObjectMapper objectMapper = new ObjectMapper();
  23.                 objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  24.  
  25.                 objectMapper.readValue(JSON, MyBean.class);
  26.         }
  27. }