In this post under JJWT I will show with example how to check whether a JWT is secured or not. JwtParser class has a “isSigned” method which will figure out whether the JWT is secured or not. All we need is to pass the test JWT string as an argument to this method. This method…… Continue reading Checking whether JWT is secured or not
Tag: JSON
Parsing simple unsecured JWT containing claims
In this post under JJWT, I will show with example how to parse a simple unsecured JSON Web Token containing claims as payload. Below is the complete main code for your reference Main class 1 package defaultPackage;2 import io.jsonwebtoken.Claims;3 import io.jsonwebtoken.Header;4 import io.jsonwebtoken.Jwt;5 import io.jsonwebtoken.JwtParser;6 import io.jsonwebtoken.JwtParserBuilder;7 import io.jsonwebtoken.Jwts;8 9 public class Example2 {10 public…… Continue reading Parsing simple unsecured JWT containing claims
Creating a simple unsecured JSON Web Token containing claims
In this post under JJWT, I will explain how to create a simple unsecured JSON Web Token whose payload is a set of claims. I will be using JJWT framework for this example and for all the upcoming examples under JJWT. Below is the complete code for your reference Main class 1 package defaultPackage;2 3…… Continue reading Creating a simple unsecured JSON Web Token containing claims
ExclusionStrategy example during serialization of object
In this post under Gson, I will explain how we can exclude certain fields of a class from being serialized with an example. Below is the Employee class structure that we want to serialize Employee public class Employee { private int id; private String name; private int ssn; private boolean terminated; public int getId() {…… Continue reading ExclusionStrategy example during serialization of object
Annotation Since and setVersion method
In this post under Gson, I will explain with an example how to use @Since annotation. The @Since annotation is used in combination with “GsonBuilder.setVersion” method. The annotation has no effect if it is not used along with “GsonBuilder.setVersion” method. The @Since annotation is used for the fields of the class and it accepts a…… Continue reading Annotation Since and setVersion method
Annotation Until and setVersion method
In this post under Gson, I will explain with an example how to use @Until annotation. The @Until annotation is used in combination with “GsonBuilder.setVersion” method. The annotation has no effect if it is not used along with “GsonBuilder.setVersion” method. The @Until annotation is used for the fields of the class and it accepts a…… Continue reading Annotation Until and setVersion method
FieldNamingStrategy Example
In my previous post “FieldNamingPolicy Example”, I explained with an example how to change the naming convention using out of the box provided standard naming conventions. In this post, I will explain with an example how to create your own custom naming conventions and configure the Gson to use it. To create our own custom…… Continue reading FieldNamingStrategy Example
Configuring Gson to serialize objects with fields having null value
Whenever we serialize a java object to JSON using Gson framework, by default fields with null values are ignored. As shown in the below code Main code import com.google.gson.Gson; public class GsonDemo7 { public static void main(String[] args) { Student student = new Student(); student.setId(1); student.setName(“name1”); student.setRollnum(100); student.setDate(null); Gson gson = new Gson(); String result…… Continue reading Configuring Gson to serialize objects with fields having null value
Using Custom DateFormat
In this post, under GSON, I will explain how to use custom date format when serializing Java object containing date information to json format. We can change this format globally, globally meaning the custom format will be applied to all objects that are serialized using Gson instance, created using the custom date format. Below is…… Continue reading Using Custom DateFormat
Configuring Gson object
In this post under GSON, I will explain how to configure the Gson instance. In all my previous post under GSON, I used to create a Gson instance by using the below code snippet. Gson gson = new Gson(); With this instance we used convert java object to and from JSON format. This instance comes…… Continue reading Configuring Gson object