Spring Boot Endpoint returning both XML AND JSON with Jackson

Поделиться
HTML-код
  • Опубликовано: 4 окт 2024
  • Use Jackson to control the xml output and set the list wrapper with annotations.
    Enjoy! :-)
    Thank you for commenting and asking questions.
    Get 25 % discount on your Minecraft servers at Shockbyte.com by using this referral link:
    shockbyte.com/...
    The code is located here:
    github.com/eki...
    Follow me on twitter:
    / mikemoelnielsen
    Support me on Patreon:
    / mikemoellernielsen
    As an Amazon Associate I earn from qualifying purchases.
    Check out the stuff that I like (always updated):
    kit.co/MikeMoe...

Комментарии • 20

  • @SpookHam
    @SpookHam 4 года назад +1

    Amazing support and feedback. Thank you so much!

  • @SpookHam
    @SpookHam 4 года назад +1

    Your videos have really helped me a lot and inspired me. When the day comes, I will also make a RUclips page like you, to teach other people what I know =)

    • @MikesTechCorner
      @MikesTechCorner  4 года назад

      Its a lot of fun creating videos. I started with just creating some vavr (javaslang) videos for a geek-get-to-gether arrangement and now I cant stop. :-) The best thing is the interaction with the community.

  • @AmNotLegend
    @AmNotLegend 4 года назад +1

    @JacksonXmlElementWrapper to indicate wrapper name to use for a Collection type

  • @bahali2
    @bahali2 2 года назад +1

    How do I get rid of the default prefix being prepended when I am using namespaces? `wstxns` is added before the name of the namespace.

    • @MikesTechCorner
      @MikesTechCorner  2 года назад

      Good question. I don't remember but it is possible to tweak the parsers to change namespace.

  • @diedrich9940
    @diedrich9940 4 года назад +1

    I am trying to create converter from XML to JSON and vice versa (in java) and I was thinking of creating program that is going to follow at least first 6 out of 7 rules from this site: www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html
    I was thinking of using recursion for this, so when user gives me some XML file or string I would use my function which would allow me to visit all data presented by user and automatically (as function is reading it) switch it in JSON format (or I would just create a new file/string with all data needed to make conversion to JSON and then convert it to JSON by applying those rules before mentioned). Same would be done for JSON file or string input. Is this possible, and how would you suggest me to approach this problem? Could you make video on that or something, would be really thankful. Also I've spent bunch of time on internet trying to find acceptable solution for this, but sadly wasn't able to do so. Thanks in advance :D

    • @MikesTechCorner
      @MikesTechCorner  4 года назад

      Use Jackson XML mapper and Jackson JSON mapper. I have videos on Rest endpoints returning both XML and JSON. Try to check those out. :-)

    • @diedrich9940
      @diedrich9940 4 года назад +1

      @@MikesTechCorner but there is no conversion logic implemented, thats just using given functions to do conversion. It's not like you get to say to a program "do mi this for this kind of input" and so on

    • @MikesTechCorner
      @MikesTechCorner  4 года назад

      It sounds very ambitious! :) i havent heard of other frameworks doing that

    • @diedrich9940
      @diedrich9940 4 года назад

      @@MikesTechCorner lol

  • @developertalk7361
    @developertalk7361 Год назад

    Thank you Mike, for this Video. This has provided solution to me after putting a lot of effort on this conversion part. however still looking for an answer, where coolSpaceship is part of other element as well. Here I am getting conflicts with reference variable in POJO, just checking if we have any alternative way. Below is sample.


    x



    y



    z






    A



    B



    C

    • @MikesTechCorner
      @MikesTechCorner  Год назад

      If you want to map to and from xml use the XmlMapper from Jackson. ObjectMapper is for JSON. Hope the answer wasn't too generic. :)

  • @sesi5289
    @sesi5289 3 года назад +1

    everybody is showing @getmapping method.I need to learn @postmapping and @putmapping but I couldnt find it :(

    • @MikesTechCorner
      @MikesTechCorner  3 года назад

      Its the same. Add @RequestBody in the method signature. Watch my other vids