Object Graph

Simple library to traverse Java object graph with fluent configuration

License

License

Categories

Categories

Net
GroupId

GroupId

net.bramp.objectgraph
ArtifactId

ArtifactId

objectgraph
Last Version

Last Version

1.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Object Graph
Simple library to traverse Java object graph with fluent configuration
Project URL

Project URL

https://github.com/bramp/objectgraph
Source Code Management

Source Code Management

https://github.com/bramp/objectgraph

Download objectgraph

How to add to project

<!-- https://jarcasting.com/artifacts/net.bramp.objectgraph/objectgraph/ -->
<dependency>
    <groupId>net.bramp.objectgraph</groupId>
    <artifactId>objectgraph</artifactId>
    <version>1.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.bramp.objectgraph/objectgraph/
implementation 'net.bramp.objectgraph:objectgraph:1.1.0'
// https://jarcasting.com/artifacts/net.bramp.objectgraph/objectgraph/
implementation ("net.bramp.objectgraph:objectgraph:1.1.0")
'net.bramp.objectgraph:objectgraph:jar:1.1.0'
<dependency org="net.bramp.objectgraph" name="objectgraph" rev="1.1.0">
  <artifact name="objectgraph" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.bramp.objectgraph', module='objectgraph', version='1.1.0')
)
libraryDependencies += "net.bramp.objectgraph" % "objectgraph" % "1.1.0"
[net.bramp.objectgraph/objectgraph "1.1.0"]

Dependencies

provided (1)

Group / Artifact Type Version
com.google.errorprone : error_prone_annotations jar 2.0.19

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
com.google.guava : guava jar 21.0
org.assertj : assertj-core jar 3.7.0

Project Modules

There are no modules declared in this project.

objectgraph

by Andrew Brampton 2014,2016

Java Build Status Maven

Simple library to traverse Java object graph. A breadth-first search is conducted on each field of each object encountered. No object is visited twice, and the algorithm is array based, so does not encounter stack overflow issues.

Maven

<dependency>
	<groupId>net.bramp.objectgraph</groupId>
	<artifactId>objectgraph</artifactId>
	<version>1.1.0</version>
</dependency>

or for Java 1.6

<dependency>
	<groupId>net.bramp.objectgraph</groupId>
	<artifactId>objectgraph</artifactId>
	<version>1.0.3</version>
</dependency>

Example

ObjectGraph
    .visitor(new ObjectGraph.Visitor() {
	    @Override
	    public boolean visit(Object object, Class clazz) {
		    System.out.println("visited " + object.toString());
		    return false;
	    }
    })
    .excludeStatic()
    .excludeTransient()
    .traverse( myObject );

Use Cases

We were encountering an issue where Hibernate entities were accidentally being stored in a HTTP session. This can cause a number of issues. To help alert new developers to this issue, a Servlet filter was created that during development would search the session for any Hibernate entities. If a entity was found, a friendly message would be displayed to encourage the developer to fix the problem.

This library has numerous other uses cases, however, in its current form the API is not well suited for serialising a object graph

Build and Release

To build this project use mvn.

To push a release to maven central use the standard maven release plugin, and Sonatype's OSS repo:

mvn release:prepare
mvn release:perform

Licence

Copyright (c) 2014,2016, Andrew Brampton
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Versions

Version
1.1.0
1.0.3
1.0.2
1.0.1
1.0