Skip to content
Branch: master
Go to file

Latest commit


Failed to load latest commit information.
Latest commit message
Commit time

JavaBean Marshaller

The JavaBeanMarshaller utility class is responsible for serializing an object (graph) to it's Java code. The objects from the graph have to follow the JavaBean convention. And by Java code, we talk calling getters and setters of all the object graph.

The main purpose of this tools is to help developer to create realistic data sets or stubs for their unit tests. Instead of using XML or JSON serialization, dataset are generated into the Java language. This format is more appropriate for performance and refactoring purpose.


  • Primitive types and their wrapper classes
  • Enumeration
  • Collection and Map
  • Arrays (1 and 2 dimensions)
  • java.util.Date, java.sql.Date, Calendar, XMLGregorianCalendar
  • Java 8 Date & Time API (JSR-310)
  • JodaTime
  • Unidirectional and bidirectionnal relationships
  • Cyclic graph


Let's imagine an in memory artist instance with a single album. UML class diagramm

Call the generateJavaCode method:


At the working directory, the java class is generated:

import com.javaetmoi.javabean.domain.Album;
import com.javaetmoi.javabean.domain.Artist;
import com.javaetmoi.javabean.domain.ArtistType;
import java.time.LocalDate;
import java.time.Month;
import java.util.ArrayList;

public class ArtistFactory {
  public static Artist newArtist() {
    Artist artist1 = new Artist();
    ArrayList<Album> albums1 = new ArrayList<>();
    Album album1 = new Album();
    album1.setReleaseDate(LocalDate.of(1987, Month.MARCH, 9));
    album1.setName("The Joshua Tree");
    return artist1;


  • Java 7 or above
  • Your JavaBeans should have of a no-arg constructors and getter/setter

Quick Start

Download the jar though Maven:


JavaBean Marshaller artefacts are available from Maven Central

Maven Central

In your application code, select a point o add the generateJavaCode method call:


Run your application and play the scenario.

To support a new custome type, you have to implement the CodeGenerator interface then call the JavaBeanMarshaller::addCodeGenerator method.

Getting Help

This file contains the main documentation.

There are also unit tests available to look at.

A french article titled Génération de jeux de données Java :

Contributing to JavaBean Marshaller

Github is for social coding platform: if you want to write code, we encourage contributions through pull requests from forks of this repository. If you want to contribute code this way, please reference a GitHub ticket as well covering the specific issue you are addressing. Before submitting your pull request, don't forget to write a corresponding unit test.

Development environment installation

Download the code with git:

git clone git://

Compile the code with maven:

mvn clean install

If you're using an IDE that supports Maven-based projects (InteliJ Idea, Netbeans or m2Eclipse), you can import the project directly from its POM. Otherwise, generate IDE metadata with the related IDE maven plugin:

mvn eclipse:clean eclipse:eclipse

Release Note

Version Release Date Features
1.0.3 2018-07-11 Escape double quotes in String
1.0.2 2017-12-22 Add BigInteger support
1.0.1 2016-03-23 Enhance quality of the generated code
1.0.0 2016-03-19 Initial release


Build Status

  • Travis: Build Status
  • Coverage Coverage Status


Serialize an object graph to it's Java code




You can’t perform that action at this time.