Skip to content

Instantly share code, notes, and snippets.

class ExclusionStrategyImpl implements ExclusionStrategy {
private final Class<?> classTypeToSkip;
public ExclusionStrategyImpl(Class<?> classTypeToSkip) {
this.classTypeToSkip = classTypeToSkip;
}
@Override
public boolean shouldSkipClass(Class<?> claz) {
return classTypeToSkip == claz;
public class Ex35 {
public static void main(String[] args) {
Gson gson = null;
Developer developer = new Developer();
String json = null;
gson = new Gson();
json = gson.toJson(developer);
System.out.println("Default behaviuor....");
System.out.println(json);
class Developer {
@Deprecated
private int count = 45;
private String name;
private String classz;
List<String> languagesKnown;
public Developer() {
name = "ajduke";
classz = Developer.class.getCanonicalName();
Default behaviuor....
{"count":45,"name":"ajduke","classz":"in.ajduke.ap013.Developer","languagesKnown":["Java","Scala","Ruby"]}
Exclude fields with type - List
{"name":"ajduke","classz":"in.ajduke.ap013.Developer"}
Exclude fields with type - String
{"languagesKnown":[null,null,null]}
package in.ajduke.ap013;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class Example34 {
public static void main(String[] args) {
Gson gson = new Gson();
Default behaviour....
{"myField":"value1","myAnotherField":"value2"}
Fields with lower case and dashes...
{"my-field":"value1","my-another-field":"value2"}
Fields with lower case and dashes...
{"My Field":"value1","My Another Field":"value2"}
{"name":"ajduke"}
@ajduke
ajduke / JSFUN.md
Last active August 29, 2015 13:56 — forked from azat-co/JSFUN.md

JS FUNdamentals

If it's not fun, it's not JavaScript.

Expressiveness

Programming languages like BASIC, Python, C has boring machine-like nature which requires developers to write extra code that's not directly related to the solution itself. Think about line numbers in BASIC or interfaces, classes and patterns in Java.

On the other hand JavaScript inherits the best traits of pure mathematics, LISP, C# which lead to a great deal of expressiveness (and fun!).

@ajduke
ajduke / task.java
Last active August 29, 2015 13:57
desc
public class Task1 {
public static void main(String[] args) {
// run in a second
final long timeInterval = 1000;
Runnable runnable = new Runnable() {
public void run() {
while (true) {
// ------- code for task to run
import java.util.Timer;
import java.util.TimerTask;
public class Task2 {
public static void main(String[] args) {
TimerTask task = new TimerTask() {
@Override
public void run() {
// task to run goes here