On Mon, Jul 6, 2020 at 2:45 AM Rahul Kumar <[email protected]> wrote: > > Thanks Tatu ! > So in that case , is it possible to write custom yaml deserializer in jackson > (to read the comments) just like we write custom Json deserializer ? > like > public class CustomDeserializer extends JsonDeserializer<SortedMap<String, > Object>> {}
No, that would require Jackson to actually get an somehow expose comments: there is no token type that would match, and I am not sure SnakeYAML even reports them in the first place. You can possibly write comments if you hold on to instance to underlying Writer, use generator.flush(), but I don't think there is way through API to see comments. -+ Tatu +- > > On Sat, 4 Jul 2020 at 05:28, Tatu Saloranta <[email protected]> wrote: >> >> On Fri, Jul 3, 2020 at 4:25 PM Rahul Kumar <[email protected]> wrote: >>> >>> Hi geeks, >>> I have a Yaml like below as below: >>> --- >>> # mY yaml variable >>> var1: ok >>> >>> I dont want to ignore comments while serialization and i wanted to take >>> them into account ? How can i do that ? >>> My code is like below (which ignores call comments) >>> >>> ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); >>> >>> Object user = mapper.readValue(yamlfile,new TypeReference<Map<String, >>> String>>() {}); >>> >>> >>> I want to use this feature to read some meta data written on top of Yaml >>> variables in the form of comments ? Does jackson allows this ? >>> >>> >> >> There is no way to currently add comments with Jackson YAML generator. >> Comments are ignored when reading content (I think SnakeYAML automatically >> discards them) and there is no current mechanism to inject them on >> serialization side. >> >> -+ Tatu +- >> >> >> >> -- >> 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 view this discussion on the web visit >> https://groups.google.com/d/msgid/jackson-user/CAGrxA241dJ7Oex5P86ddG-AeX_oY6h5sYLCxNYSK3LpEb3shCg%40mail.gmail.com. > > -- > 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 view this discussion on the web visit > https://groups.google.com/d/msgid/jackson-user/CAGH8rExm%3D8NwEsGNXVaU0bysTYOHtjrFQJ8%3DD390icQ0Ao5yPw%40mail.gmail.com. -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CAL4a10iKFvU%2ByDDmG-rGCDW4s%2B9Vh%2BOhkMEYJ-F0dxvSKnhA1g%40mail.gmail.com.
