elstar IT

Fullstack | Java | Tech Speaker | Tech Coach | Frank van der Linden

  • About me
  • Blog license
  • My Open source projects

Jackson JSON mapper plugin for XPages

13-02-2015 4 responses flinden68 development

To work in Java with JSON there are several libraries, like GSON, JSON-simple and even the IBM version. They are very easy to use.

In my recent J2EE projects their was always a need of consuming JSON and returning JSON. The library we used their was Jackson JSON library.

It was a refreshing way to work with JSON without building or consuming it line by line. Jackson is mapping JSON directly to POJO. So with one line of code the JSON is transformed to a real Java Object and can be used all over your project.

[dropshadowbox align=”none” effect=”lifted-both” width=”400px” height=”” background_color=”#ffffff” border_width=”1″ border_color=”#dddddd” ]

private ObjectMapper mapper = new ObjectMapper();

mapper.readValue(data, Message.class)[/dropshadowbox]

The other way around it also very easy, write your POJO directly to the output writer, like a File or mostly the response of a servlet, which we used in our projects.

[dropshadowbox align=”none” effect=”lifted-both” width=”400px” height=”” background_color=”#ffffff” border_width=”1″ border_color=”#dddddd” ]

mapper.writeValue(response.getWriter(), message);

[/dropshadowbox]

Where message is a POJO, and data is JSON as String

 

Inside a NSF

I was thinking to make it available to a XAgent. First I included the 3 libraries the lib directory under WEB-CONTENT inside my NSF and add them to the build path.

Immediately I a was able to use the code in my Java class. So it worked, but…. if I want to use it in another NSF I need  to perform the above steps.

 

OSGi plugin

There started the idea to put everything in an OSGi plugin, so all the NSF’s on the Domino server can benefit from it.

I put everything in a plugin project, thanks to the great blog of John Dalsgaard,

Created a feature and update site and put everything on a Bitbucket repository, so everyone can use it.

 

Security

To get everything working you need to add a custom java policy file in side the <domino directory>jvm/lib/security. You can use the java.pol file who is inside the repository. The benefit of using java.pol is that after an upgrade or what ever, the java.pol file is not affected.

 

Have fun with it…

 

Tags: jackson, json, xpages

4 thoughts on “Jackson JSON mapper plugin for XPages”

  1. Nick Wall says:
    13-02-2015 at 10:25

    Great stuff. We use Jackson and have the files inside our NSF, this will help a lot with other projects, thanks!

    Reply
  2. Patrick Kwinten says:
    05-05-2015 at 09:57

    Hi Frank,

    can you share some sample code how the consumer class could look like?

    Reply
  3. patrick kwinten says:
    09-05-2015 at 21:34

    Hi frank,

    I am learning the Jackson library and it’s capabilities. Do you have any code to share how you can use it with XPages? E.g. I am looking for a solution to provide an infinite scroll functionality in combination with Domino Access Services.

    Any tip is helpful (and appreciated) =)

    Reply
    1. Frank van der Linden says:
      12-05-2015 at 12:07

      What kind of code you are looking for?

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • « 2014 was a year of change
  • My take on a Multi Growl messages phaselistner for XPages »

Contact me

My name is Frank van der Linden and I am an independent software developer based in the Netherlands. The last 2 years I was awarded as IBM Champion. Also I am on the board of OpenNTF. My specialisations are Java, Web development and Domino.


If you want to hire me, please fill in the Contact form


IBM Champion web badge
Apache Logo

All the code on this blog are under the Apache License 2.0. For more details, see Apache License 2.0

Most recent posts

  • Engage 2020: Hello are you listening, There is stream for everything
  • Spring Cloud Function on Azure run locally
  • Deploy Spring Cloud Function to IBM Cloud
  • Speaking (again) at Engage in a Zoo
  • Congratulations, you’re an IBM Champion (again)!

Latest reactions

  • Spring Cloud Function on Azure run locally - elstar IT on Deploy Spring Cloud Function to IBM Cloud
  • flinden68 on Quick XPages tip: add Fullcalendar plugin to your application
  • Rajesh samal on Quick tip: Swagger support for Spring Webflux
  • dsieyx on Quick XPages tip: add Fullcalendar plugin to your application
  • John on Named as IBM Champion 2019

Archive

  • March 2020
  • February 2020
  • January 2020
  • October 2019
  • September 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • January 2019
  • December 2018
  • October 2018
  • September 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014

Category

  • bluemix
  • business
  • cloudant
  • community
  • development
  • hrassistant
  • openntf
  • running
  • salesforce
  • Springboot
  • Tesla
  • trailrunning
  • Uncategorized
  • watson
  • OpenNTF
  • Collaboration Today
  • XSnippets
  • Stackoverflow
  • IBM Collaboration Solutions
  • Social Business Toolkit
  • About me
  • Dutch curriculum vitae
  • English curriculum vitae
  • Google+
  • LinkedIn profile
  • Twitter
  • Slideshare
  • Blog license
  • My open source projects