To answer your question directly:
To skip a value just annotate it with "@JsonIgnore".

But i guess you want good values, instead of skipping them.
To get a good LocalDate from Jackson, confige the ObjectMapper with the 
following feature:

"objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);"

and then annotate the LocalDate property with:

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = 
"UTC")


This should give you a good LocalDate Value.



Am Samstag, 6. Juli 2019 10:20:14 UTC+2 schrieb gurpal2000:
>
> 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 jackson-user+unsubscr...@googlegroups.com.
To post to this group, send email to jackson-user@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/ad4f2e02-7308-4be6-a424-dd8ff1c1b648%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to