Java library to provide an API for beans and properties.

Overview

Joda-Beans

Joda-Beans provides a small framework that adds properties to Java, greatly enhancing JavaBeans. An API is provided that defines a bean and property model, together with a code generator to make it work in practice.

The key concept is to allow each property on a bean to be accessed as an object. This enables technologies such as XPath, XML conversion, DB mappings, WebApp validation and Swing bindings.

Joda-Beans is licensed under the business-friendly Apache 2.0 licence.

Why Joda Beans?

Joda-Beans has been created to plug a gap in the Java language - properties. The concept of properties is familiar to those coding in almost every other modern language. Java stands alone in its pursuit of the terrible JavaBean approach, and personally I believe that properties should have been added to Java before generics and closures.

JavaBeans are typically created by manual coding or one-off IDE generation, such as by Eclipse. The same approach is taken to the creation of equals and hashCode methods. However, none of these approaches provides for a simple and fast mechanism to query a bean for the properties it exposes.

Joda-Beans provides a solution. As a developer, you just write the fields much as you would today. Then you add annotations to the bean and properties. Finally, you run a code generator, which creates the get/set methods plus framework methods that allow the properties to be effectively queried. If you use Eclipse and the Joda-Beans Maven plugin, the bean will be regenerated automatically on save.

A key point is that the code generator may be run again and again on the Java file, and is non-destructive. See these sample classes used for testing - a simple user account class, example usage, example of validation.

Documentation

Various documentation is available:

Releases

Release 2.8.1 is the current release. This release is considered stable and worthy of the 2.x tag. There are only minor incompatibilities with the 1.x codebase.

Joda-Beans requires Java SE 8 or later and depends on Joda-Convert. There are a number of optional dependencies which help with integration.

Available in the Maven Central repository

For Java SE 6 compatibility, use release 1.14.

Tidelift dependency check

For enterprise

Available as part of the Tidelift Subscription.

Joda and the maintainers of thousands of other packages are working with Tidelift to deliver one enterprise subscription that covers all of the open source you use.

If you want the flexibility of open source and the confidence of commercial-grade software, this is for you.

Learn more

Support

Please use Stack Overflow for general usage questions. GitHub issues and pull requests should be used when you want to help advance the project.

Any donations to support the project are accepted via OpenCollective.

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Release process

  • Update version (README.md, index.md, changes.xml)
  • Commit and push
  • Switch to Java 11
  • mvn clean release:clean release:prepare release:perform
  • git fetch
  • Website will be built and released by GitHub Actions
Comments
  • Joda-beans 2.1 not compatible with OW2 ASM 5.0

    Joda-beans 2.1 not compatible with OW2 ASM 5.0

    Not certain but is seems that joda-beans 2.1 (or one of it's transitive dependencies) on the maven repo was compiled with Java 9. This is causing an issue running a web service in TomEE 8.5 given that there is a dependency in tomcat on the ASM 5.0 bytecode manipulation library which only supports <= Java8.

    Fixed Discussion 
    opened by ghost 7
  • How to treat beans split up into interface and implementation

    How to treat beans split up into interface and implementation

    So i have two OSGi bundles, one with interfaces, one with implementations. Lets say, i have public interface Person in one bundle, and public class PersonImpl implements Person in th other. I would like to generate getters, setters and addPropertyChangeListener() in the interface, and the implementations of those in the class. Is this possible with JodaBeans, and if so, how? If not, can you recommend some other library or tool that can do this? ...or am i not seeing some fundamental problem about this idea here?

    Discussion 
    opened by hoijui 6
  • How to wrap a map in a bean/ round trip?

    How to wrap a map in a bean/ round trip?

    I have been kicking the tires on this project for a while.

    This should be doable but I am wondering best way: Make a Bean from Map?

    {Also it be nice to go the other way. Map m = toMap(Bean) }

    Cheers

    Discussion 
    opened by ghost 5
  • Observable property - feature request

    Observable property - feature request

    Hi Would you please add "Observable property" feature by invoking firePropertyChange in generated setter method? This also requires to generate addPropertyChangeListener and removePropertyChangeListener methods ,plus PropertyChangeSupport field.

    This could be controlled by extending @PropertyDefinition with "observable=true" attribute.

    Thanks Alexander

    RFE Fixed 
    opened by jvmlet 5
  • Support for custom property names for mapping and json

    Support for custom property names for mapping and json

    Hi

    I am excited to see you added json serialization, because I am guessing that it is going to be faster much faster than components that use reflection or annotations. One component that is missing is the capability to set custom json field names.

    Jackson allows the setting of field names via annotations such as:

    @JsonProperty("name")

    Is it possible to have the same type of support for both json and map instantiation of properties?

    RFE 
    opened by chrislovecnm 4
  • Checkstyle OFF/ON block comments

    Checkstyle OFF/ON block comments

    I have a projects with 50 JPA objects, but they produce about ~40,000 Checkstyle warnings, with ~39,950 are within the AUTOGENERATED section. So 50 are in code I author.

    Working on PR to add //CHECKSTYLE:OFF and //CHECKSTYLE:ON within the auto generated section. Associated PR will be raised shortly for early early review.

    Discussion 
    opened by nhojpatrick 3
  • Support one-line property definitions

    Support one-line property definitions

    Currently one-line property definitions are not supported:

    @PropertyDefinition private String forename;
    

    has to be changed to:

    @PropertyDefinition
    private String forename;
    

    It would be great, if one-line property definitions would be supported, because that's the way google/google-java-format formats simple fields.

    RFE 
    opened by mkroening 3
  • "Unable to locate field type" error when annotations below @PropertyDefinition contain newlines

    Hi, I have a property definition with JPA annotations of the form:

    @Entity
    @BeanDefinition(builderScope = "public")
    public class MyDomainObject implements Bean {
    
        @PropertyDefinition
        @ManyToOne(fetch = FetchType.EAGER)
        @JoinTable(name = "MY_JOIN_TABLE",
                inverseJoinColumns = { @JoinColumn(name = "AN_ID") },
                joinColumns = { @JoinColumn(name = "ANOTHER_ID") })
        private MyObject myObject;
    
    

    Upon saving in eclipse I get "Unable to locate field type at line X", if I remove the nested @JoinColumn lines it works. It also works if there's one nested @JoinColumn annotation on a single line.

    Maven plugin version 1.1, joda beans version 1.13.

    This issue was originally posted at https://github.com/JodaOrg/joda-beans-maven-plugin/issues/4

    RFE Fixed 
    opened by lourish 3
  • Alias Query

    Alias Query

    Reading the documentation, specifically regarding @PropertyDefinition alias. Using the below example I would expect it to generate getCase and setCase methods, but generates getACase and setACase instead.

    @BeanDefinition
    public class AliasQuery
            implements Bean {
        @PropertyDefinition(alias = "case")
        private String aCase;
    }
    

    I've got several POJO's I would like to switch over to using Joda Beans, but because the name conflicts with a keyword the private variable is often prefixed with '_' or a and the getter and setter have slightly different names. e.g. getCase/setCase and getLong/setLong.

    Am I missing something from the documentation which might aid me switching to Joda Beans without having to do a mass refactoring exercise.

    Discussion 
    opened by nhojpatrick 3
  • Add support for directly deserializing Guava immutable collections

    Add support for directly deserializing Guava immutable collections

    Adds explicit support for ImmutableList, ImmutableSet, ImmutableSortedSet and ImmutableMap. This allows objects to be serialized using custom meta beans which use the deserialized value to populate the field without any copying.

    Fixes #129

    RFE 
    opened by cjkent 3
  • Fix for referencing bean format using incorrect class name with JodaConvert interfaces

    Fix for referencing bean format using incorrect class name with JodaConvert interfaces

    Currently if one serializes an immutable bean which holds under an Object reference something implementing a JodaConvert interface with multiple implementations and the type is required to be serialized then the referencing converter chooses to serialize the first concrete implementation class name it encounters, rather than that of the interface itself.

    Added a test case for it and deleted some useless code (we don't care about serializing class names for null values; also serializing classes as values is easy, just write the class name!)

    Bug Fixed 
    opened by wjnicholson 2
  • Bump assertj-core from 3.23.1 to 3.24.1

    Bump assertj-core from 3.23.1 to 3.24.1

    Bumps assertj-core from 3.23.1 to 3.24.1.

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • CodeGen mistakes equals/hashcode on inner classes for manually generated implementations

    CodeGen mistakes equals/hashcode on inner classes for manually generated implementations

    Example class:

    @BeanDefinition
    public final class Example implements ImmutableBean {
    
      @PropertyDefinition(validate = "notNull")
      private final String exampleProperty;
    
      private static class ExampleInner {
    
        private final String innerProperty;
    
        private ExampleInner(String innerProperty) {
          this.innerProperty = innerProperty;
        }
    
        @Override
        public boolean equals(Object o) {
          if (this == o) {
            return true;
          }
          if (o == null || getClass() != o.getClass()) {
            return false;
          }
          ExampleInner that = (ExampleInner) o;
          return Objects.equals(innerProperty, that.innerProperty);
        }
    
        @Override
        public int hashCode() {
          return Objects.hash(innerProperty);
        }
      }
    }
    

    JodaBean's code gen spots the implementations of equals and hashcode on ExampleInner and decides to omit generating implementations itself (line 617, in org.joda.beans.gen.BeanParser from the looks of things).

    Given the code gen doesn't have a true understanding of class structure perhaps an additional flag on the @BeanDefinition could provide an override of the heuristic being applied?

    Can simply work around the issue for now by extracting the inner class into its own file but raising this issue for visibility.

    RFE 
    opened by ashleyheath 1
  • Referencing Binary Format: Remove references to collections

    Referencing Binary Format: Remove references to collections

    Currently BeanReferences increments counts for values that are collection types, when we never serialize references for collections. Doesn't affect serialization massively, but without we could be using a smaller references array / more efficient reference numbers. e.g in the test example, previously the letters "A" and "B" used references 5 and 6, rather than the 1 and 2 that they should have been (as the most common item to be referenced).

    Can't really change the code to reuse collections, as some types of collections are a bit hairy, what if it's first read as Set but later we serialize a SortedSet with the same elements? Can't reuse the original value but instead need a copy constructor, and that's a lot of effort to code. If somebody really wanted that effect they could wrap the collection in an ImmutableBean and get the deduplication for free.

    opened by wjnicholson 0
  • Parsing json fails when Bean does not contain fields, but parent class has them

    Parsing json fails when Bean does not contain fields, but parent class has them

    Suppose you have next model:

    public abstract class ReportBaseColumn implements ImmutableBean {
        @PropertyDefinition(validate = "notNull")
        protected final String name;
    
        public ReportBaseColumn(String name) {
            this.name = name;
        }
    }
    
    @BeanDefinition(builderScope = "public")
    public class ReportAliasColumn extends ReportBaseColumn {
        public ReportAliasColumn(String name) {
            super(name);
        }
    
        public String getType() {
            return "ALIAS";
        }
    }
    
    @BeanDefinition(builderScope = "public")
    public class ReportSimpleColumn extends ReportBaseColumn {
        public ReportSimpleColumn(String name) {
            super(name);
        }
    
        public String getType() {
            return "SIMPLE_COLUMN";
        }
    }
    

    So after running code generation, Builder will contain next code for ReportAliasColumn & ReportSimpleColumn :

            @Override
            public Object get(String propertyName) {
                throw new NoSuchElementException("Unknown property: " + propertyName);
            }
    
            @Override
            public Builder set(String propertyName, Object newValue) {
                throw new NoSuchElementException("Unknown property: " + propertyName);
            }
    
    

    Then we can try to create new insatnce of ReportAliasColumn and serialize is to JSON:

    ReportColumn col = new ReportAliasColumn("abc");
    String json = JodaBeanSer.COMPACT.jsonWriter().write(col);
    System.out.println(json);
    

    the output will be:

    {"@bean":"ReportAliasColumn","name":"abc"}
    

    But when we try to deserialize this json back to ReportAliasColumn, using next code

    ReportAliasColumn alias = JodaBeanSer.COMPACT.jsonReader()
        .read(json, ReportAliasColumn.class);
    

    we will get exception:

    java.lang.IllegalArgumentException: Error parsing bean: ReportAliasColumn::name, Unknown property: name
    

    Thats happen because of behaviour of code generator: org.joda.beans.gen.BeanGen#generateBuilderSet

    When particular bean has no fields, then it simply generate code

    data.ensureImport(NoSuchElementException.class);
    addLine(3, "throw new NoSuchElementException(\"Unknown property: \" + propertyName);");
    

    I think it will be better to use the same logic as in default block when there are fields, i.e.:

                if (data.isRootClass()) {
                    data.ensureImport(NoSuchElementException.class);
                    addLine(3, "throw new NoSuchElementException(\"Unknown property: \" + propertyName);");
                } else {
                    addLine(3, "super.set(propertyName, newValue);");
                }
    
    Discussion 
    opened by troshanin 3
  • Builder methods for adding individual items to Collection and Map properties (WIP)

    Builder methods for adding individual items to Collection and Map properties (WIP)

    First pass at add and put methods for building collections and maps within beans (see #100).

    • Creates addPropertyName(value) methods for collections and one-dimensional arrays within beans. Higher-dimensional arrays are currently ignored.
    • Creates putPropertyName(key, value) methods for maps within beans.
    • The add and put methods use immutable builders to create new instances of the appropriate collection with the new element appended. This is presumably less efficient than initialising the bean builder with instances of the collection builders and simply adding to them - however that looks like it would require a significant re-write of the builder generation code.
    • Does not currently attempt to translate the property name into its singular value but this wouldn't be difficult to add (and for my money is nicer). Probably should also have a new property on the @PropertyDefinition annotation (singular?) to allow overriding when the 'smart' generation picks something nonsensical or that clashes with other code.
    • All maps and collections are currently constructed using guava's immutable builders. Not sure what the expected collection implementations are for mutable beans?
    • The NavigableSet, NaviableMap, Grid, and ImmutableGrid types are not currently supported (due to not having a equivalent builders.
    • For put(key, value) methods, the javadoc for key states that it shoud be non-null but the javadoc for the value does not.
    opened by ashleyheath 0
  • Null Double parsed as NaN

    Null Double parsed as NaN

    I think there is some ambiguity in how the null numeric values are parsed. Or, at least, it would be nice to have a somehow configurable behaviour.

    Here is the issue. I have this bean:

    @PropertyDefinition(validate = "notNull")
    private final Double number;
    

    When I parse the following jsons (which should represent the same content) I get two different results

    {"number":null} --> number=Double.NaN
    {} --> number=null --> IllegalArgumentException("Argument number must not be null")
    

    I expected to get the exception in both cases. What do you think?

    I noticed that AbstractJsonReader leniently accepts null as NaN. Would it be possible to change this in your opinion?

    Discussion 
    opened by ertasso 1
Releases(v2.8.3)
Annotation processor to create immutable objects and builders. Feels like Guava's immutable collections but for regular value objects. JSON, Jackson, Gson, JAX-RS integrations included

Read full documentation at http://immutables.org // Define abstract value type using interface, abstract class or annotation @Value.Immutable public i

Immutables 3.2k Dec 31, 2022
adt4j - Algebraic Data Types for Java

adt4j - Algebraic Data Types for Java This library implements Algebraic Data Types for Java. ADT4J provides annotation processor for @GenerateValueCla

Victor Nazarov 136 Aug 25, 2022
A collection of source code generators for Java.

Auto A collection of source code generators for Java. Auto‽ Java is full of code that is mechanical, repetitive, typically untested and sometimes the

Google 10k Jan 5, 2023
Automatic generation of the Builder pattern for Java

FreeBuilder Automatic generation of the Builder pattern for Java 1.8+ The Builder pattern is a good choice when designing classes whose constructors o

inferred.org 797 Dec 19, 2022
Very spicy additions to the Java programming language.

Project Lombok Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java. Never write another g

Reinier Zwitserloot 11.7k Jan 1, 2023
Source Code for BlueEagle jRAT & Release ☄ 📏☣✒Blue Eagle jRAT is a cross platform RAT tool (java RAT) / (jRAT)

Source Code for BlueEagle jRAT & Release ☄ ??☣✒Blue Eagle jRAT is a cross platform RAT tool (java RAT) / (jRAT) which is { [Windows RAT] [Linux RAT] [MAC RAT] } which is fully programmed in java be a user friendly and easy to use and builds out trojans (.jar) and controls the victims running those trojans on same port at same time ,this tool is fully in java (Client & Server in java) and this tool is now registerd to be free , and on the user responsibility

SaherBlueEagle 25 Sep 26, 2022
QuickPerf is a testing library for Java to quickly evaluate and improve some performance-related properties

QuickPerf is a testing library for Java to quickly evaluate and improve some performance-related properties quickperf.io ?? Documentation Annotations

null 365 Dec 15, 2022
A lightweight and extensible library to resolve application properties from various external sources.

Externalized Properties A lightweight and extensible library to resolve application properties from various external sources. Twelve Factor Methodolog

Joel Jeremy Marquez 20 Nov 29, 2022
A lightweight and extensible library to resolve application properties from various external sources.

Externalized Properties A lightweight and extensible library to resolve application properties from various external sources. Twelve Factor Methodolog

Joel Jeremy Marquez 20 Nov 29, 2022
Netflix, Inc. 809 Dec 28, 2022
[INACTIVE] Avian is a lightweight virtual machine and class library designed to provide a useful subset of Java's features, suitable for building self-contained applications.

Avian - A lightweight Java Virtual Machine (JVM) PLEASE NOTE: This project is not currently being developed, maintained, or supported. Feel free to us

ReadyTalk 1.2k Dec 22, 2022
A library that provide informations for minecraft servers (players, maxplayers and motd)

MinecraftServerInformations MinecraftServerInformation is a java library for retrieving informations about Minecraft Servers. Installation Download th

null 10 Sep 11, 2022
A Spigot plugin to edit block properties and more.

BoneTool BoneTool is a tool created to edit block properties with many features for builders. This is a creative tool developed as a package of featur

DeZilla 1 Jan 6, 2022
An efficient, up-to-date reader/writer for Java properties files

JProperties JProperties is a small, highly efficient, and extensible library for parsing .properties files. It is a modern replacement for the java.ut

Aidan 12 Apr 1, 2022
jdbi is designed to provide convenient tabular data access in Java; including templated SQL, parameterized and strongly typed queries, and Streams integration

The Jdbi library provides convenient, idiomatic access to relational databases in Java. Jdbi is built on top of JDBC. If your database has a JDBC driv

null 1.7k Dec 27, 2022
Get rid of the boilerplate code in properties based configuration.

OWNER OWNER, an API to ease Java property files usage. INTRODUCTION The goal of OWNER API is to minimize the code required to handle application confi

lviggiano 874 Dec 31, 2022
Uber-project for (some) standard Jackson textual format backends: csv, properties, yaml (xml to be added in future)

Overview This is a multi-module umbrella project for Jackson standard text-format dataformat backends. Dataformat backends are used to support format

FasterXML, LLC 351 Dec 22, 2022
Get rid of the boilerplate code in properties based configuration.

OWNER OWNER, an API to ease Java property files usage. INTRODUCTION The goal of OWNER API is to minimize the code required to handle application confi

Matteo Baccan 874 Dec 31, 2022