This post explains how java objects can be serialized or deserialized in Spring framework Spring framework provides two interfaces and their default implementations as mentioned below Interfaces 1) Serializer 2) Deserializer Default Implementations 1) DefaultSerializer 2) DefaultDeserializer The default implementations internally uses java serialization to provide the serialization feature. In other words these implementations act…… Continue reading Serialization of objects
Global Scope and Engine Scope Bindings
This post explains about bindings and how we can use them to pass java objects to the script code. Java Scripting API provides map data structure which can be accessed, modified using Bindings Interface. The map entry’s key matches with the variable name in the script and their value can be a primitive value or…… Continue reading Global Scope and Engine Scope Bindings
Default Interface Example
Java 8 introduces a new feature called Default Interface. This feature allows interface creator to provide default implementations for methods, so that concrete classes that implementing the interface don’t have to provide implementations for those methods. The below code gives you an example of how to create default interface and how to use them. Interface…… Continue reading Default Interface Example
Creating and Writing JSON object model to a file
This post explains how to create and save json object model to a file. In the example we build the below json object model representing person information. { “ssn” : “111111111”, “name” : { “firstName” : “Ronald”, “lastName” : “Childs” }, “phoneNumbers” : [ “1112223333”, “4445556666” ] } The main code is as shown below…… Continue reading Creating and Writing JSON object model to a file
Different ways to add entry in cache
This post explains the different ways provided by JCache to add entries in a cache. The api’s are as mentioned below 1) void put(K key, V value) –> Takes key and value as argument 2) void putAll(Map map) –> Takes a map as an argument 3) boolean putIfAbsent(K key, V value) –> Takes a key…… Continue reading Different ways to add entry in cache
JCache ModifiedExpiryPolicy
This post explains ModifiedExpiryPolicy with simple example. ModifiedExpiryPolicy is an expiry policy used to inform cache to remove entries which has exceeded its presence since last modification (which includes creation and update) Main Code 1 import java.util.Iterator; 2 3 import javax.cache.Cache; 4 import javax.cache.Cache.Entry; 5 import javax.cache.CacheManager; 6 import javax.cache.Caching; 7 import javax.cache.configuration.Factory; 8 import…… Continue reading JCache ModifiedExpiryPolicy
Different ways to remove cache entry
This post explains different ways in which we can remove entries in a cache using JCache api. The JCache api provides the below methods 1) boolean remove(K key) –> remove an entry with key matching the method parameter 2) boolean remove(K key, V oldValue) –> removes an entry with matching key and value 3) void…… Continue reading Different ways to remove cache entry
JCache Expiry Policy Example
This post explains about JCache’s Expiry policy with an example. Cache’s Expiry policy is used to inform the caching provider when to remove an entry. The below code uses JCache’s CreatedExpiryPolicy as an example. CreatedExpiryPolicy is used to inform the cache provider to remove the entry after a specified time since the entry’s addition to…… Continue reading JCache Expiry Policy Example
Mocking abstract classes
This post explain mocking abstract classes for testing purposes. Note 1) This feature is not available in pre 1.10.12 release 2) We can mock abstract class only if it has parameter less constructor Below is the example of how we can do it. ClassA (Abstract Class) package package2; public abstract class ClassA { public abstract…… Continue reading Mocking abstract classes
Reading json data in non-streaming way (object model)
We can read a json file and create an object model of it, using the ObjectMapper’s readTree api. ObjectMapper class is responsible for parsing the json file and create appropriate java objects. It uses Jackson’s parsing feature internally for reading the json file. They are many overloaded method of readTree available in ObjectMapper. In this…… Continue reading Reading json data in non-streaming way (object model)