In this post under Jackson –> JSON, I will explain with example how to marshal and unmarshal a generic object. Below is the complete main code for your reference Main class 1 package package14; 2 3 import com.fasterxml.jackson.core.type.TypeReference; 4 import com.fasterxml.jackson.databind.ObjectMapper; 5 6 import java.util.ArrayList; 7 import java.util.List; 8 9 public class Example14 { 10…… Continue reading Marshalling and Unmarshalling a generic object
Tag: JSON
@SerializedName annotation example
In this post under Gson, I will explain with example the purpose of “@SerializedName” annotation. By default when we serialize an object to Json, the class field names are used as key names in the Json. For example if we have the below class structure JavaBean class structure package defaultPackage;import com.google.gson.annotations.SerializedName;import java.util.List;public class Author {…… Continue reading @SerializedName annotation example
Creating and Parsing a asymmetric key signed JWT containing claims
In this post under JJWT, I will show with example how to create and parse asymmetric key signed JWT containing claims. Below is the complete code for your reference. Main class 1 package defaultPackage; 2 import java.security.KeyPair; 3 import java.security.PrivateKey; 4 import java.security.PublicKey; 5 import java.util.Date; 6 7 import io.jsonwebtoken.Claims; 8 import io.jsonwebtoken.Jws; 9 import…… Continue reading Creating and Parsing a asymmetric key signed JWT containing claims
Creating and Parsing a asymmetric key signed JWT containing payload
In this post under JJWT, I will show with example how to create and parse asymmetric key signed JWT containin payload. The JWT can contain claims or payload. For our example we will use a JWT containing payload. Below is the complete code for your reference Main code 1 package defaultPackage; 2 import java.security.KeyPair; 3…… Continue reading Creating and Parsing a asymmetric key signed JWT containing payload
Asserting the presence of a custom claim in JWT
In this post under JJWT, I will explain with example, how to verify or assert the presence of custom (user created and added) claim in JWT token. JJWT framework provides a method through which1) we can verify whether a custom claim exist in the JWT or not.2) we can verify whether a custom claim’s value…… Continue reading Asserting the presence of a custom claim in JWT
Asserting the presence of a standard claim in JWT
In this post under JJWT, I will explain with example, how to verify or assert the presence of standard claim in JWT token. JJWT framework provides a list of methods through which1) we can verify whether a standard claim exist in the JWT or not.2) we can verify whether a standard claim’s value is equal…… Continue reading Asserting the presence of a standard claim in JWT
Creating and Parsing a secret key signed JWT containing payload
In this post under JWT, I will show with example how to create and parse a signed JWT containing payload. As mentioned in previous posts we will use an instance of “JwtBuilder” to construct a JSON Web Token. Below is the code snippet for your reference Snippet 1 1 JwtBuilder jwtBuilder = Jwts.builder();2 3 jwtBuilder.header().add(“alg”,…… Continue reading Creating and Parsing a secret key signed JWT containing payload
Parsing simple unsigned JWT containing plaintext as payload
In this post under JJWT, I will show with example how to parse unsigned JWT containing plaintext as payload instead of serialized Claims object. As shown in previous post under JJWT, whenever we need to parse a JWT string. We need to create an instance of “JwtParser” as shown below JwtParserBuilder jwtParserBuilder = Jwts.parser(); jwtParserBuilder.unsecured();…… Continue reading Parsing simple unsigned JWT containing plaintext as payload
Creating a simple unsecured JSON Web Token containing payload
In this post under JJWT, I will show with example how to generate unsecured JWT containing payload. In previous post under JJWT, I talked about JWT containing claims. So what is the difference between claims and payload. Its simple, payload is noting but any String data, whereas claims is a map. Now with the difference…… Continue reading Creating a simple unsecured JSON Web Token containing payload
Creating and Parsing a secret key signed JWT containing claims
In this post under JWT, I will show with example how to create and parse a signed JWT containing claims. As mentioned in previous posts we will use an instance of “JwtBuilder” to construct a JSON Web Token. Below is the code snippet for your recap Snippet 1 1 JwtBuilder jwtBuilder = Jwts.builder();2 3 jwtBuilder.header().add(“alg”,…… Continue reading Creating and Parsing a secret key signed JWT containing claims