Package jestr.examples.example1

This example illustrates default stringification.


Class Summary

Package jestr.examples.example1 Description

This example illustrates default stringification. You can run it via "ant -f runexample1.xml" from the root of the distribution.

The example consists of an Account class which aggregates three Balance instances and an account ID. The classes are listed below:

    public class Account {
        private Balance currentBalance = new Balance(100.00, "USD", new Date());
        private Balance endingBalance = new Balance(62.44, "USD", new Date() );
        private Balance ledgerBalance = new Balance(89.75, "USD", new Date());
        private String id = "123";

    public class Balance {
        public Balance(double amt, String curr, Date asof) {
            this.amount = amt;
            this.currency = curr;
            this.asof = asof;
        public String toString() {
            return "" + amount + " " + currency + " as of " + asof;
        private double amount;
        private String currency;
        private Date asof;

    public class RunIt {
        public static void main(String[] argv) {
            Account account = new Account();
            System.out.println( Jestr.str(account) );

The RunIt class produces the following output:

        Balance currentBalance = Balance(100.0 USD as of Fri Mar 19 22:33:11 EST 2004)
        Balance endingBalance = Balance(62.44 USD as of Fri Mar 19 22:33:11 EST 2004)
        Balance ledgerBalance = Balance(89.75 USD as of Fri Mar 19 22:33:11 EST 2004)
        String id = "123"

Note that since Balance has its own toString() method explicitly defined, this one takes precedence and is used. We will see how to override this behavior in the next example. Also note that no file is needed since we are using default settings.

Copyright (c) 2001-2003 - Apache Software Foundation