I have a pojo that includes a LocalDate (with a year, month, day populated 
only)

I then attempt to convert the member variables and object values to a 
Map<String, Object> using this:

Map<String, Object> map = objectMapper.convertValue(obj, new 
TypeReference<Map<String, Object>>() {});


In debug i'm seeing that my Map contains a LinkedHashMap for the LocalDate!


I need to pass this to a JDBC prepared statement and obviously LinkedHashMap 
makes no sense to it.


How do I get the Object Mapper to skip all instances of LocalDate or a specific 
field? I'm using spring boot 2.1.4?


If I use something like this function which uses reflection all is well. But 
i'd rather use ObjectMapper if possible.


public Map<String, Object> pojoToMap(Object obj) {
  Map<String, Object> hashMap = new HashMap<String, Object>();
  try {
    Class<? extends Object> c = obj.getClass();
    Method m[] = c.getMethods();
    for (int i = 0; i < m.length; i++) {
      if (m[i].getName().indexOf("get") == 0) {
        String name = m[i].getName().toLowerCase().substring(3, 4) + 
m[i].getName().substring(4);
        hashMap.put(name, m[i].invoke(obj, new Object[0]));
        hashMap.remove("class"); // remove class
      }
    }
  }
  catch (Throwable e) {
    // TODO: log error
  }
  return hashMap;
}


thanks

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/7cb74ef3-026e-4d34-bd17-1ea0ac11b298%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to