开发者

commons beanutils alternative

I am looking for a commons beanutils alternative. The reason is that 开发者_如何学Gobeanutils relies on commons-logging which is conflicting with existing libraries I am using.

I would like a small self-contained alternative which will cause no/minimal conflicts.

The main functionality I am after is nested property retrieval.

Thanks in advance, Steven


While property handling is not the main focus of Jackson, it can be used for that, as per this article.

The basic idea is that you can not only read/write JSON to/from POJOs, but also do compatible conversions: including that of "serializing" a POJO as a Java Map. Since you can go back and forth between representations you basically get a bean introspector for free.

Jackson has no external dependencies, but you need both core (streaming api, impls) and mapper jars (data binding).


Jodd has very good collection of libraries, See if Jodd BeanUtil helps.


You may be able to resolve the conflict with commons-logging by using the alternate commons-logging bridge implementation provided by SFL4j.

Often times, replacing commons-logging.jar with jcl-over-slf4j.jar will immediately and permanently solve class loader issues related to commons logging.


Ended up writing my own mini beanutils to get around this dependency and removed commons-beanutils completely.

The SLF4J did not end up helping since it broke some other dependencies (damn you weblogic!).

My own implementation is probably slower since the commons-beanutils appears to cache some fetches to remove some reflective calls.

Msg me if your interested in getting the source code of my implementation.


If you are using Maven, you can exclude the commons-logging dependency like this:

<dependency>
    <groupId>commons-beanutils</groupId>
    <artifactId>commons-beanutils</artifactId>
    <version>1.8.3</version>
    <exclusions>
        <exclusion>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>

I've done the same with Spring, which also requires commons-logging. In fact Spring themselves taught me how to exclude it. As far as I can tell, I now have a commons-logging-free environment.

Update: for something like SLF4J / Logback, you may also need this in your config file:

<logger name="org.apache.commons" level="OFF" />


A valid alternative with no conflicts with other libraries is BULL, you can find a guide on how to use it on DZone. It offers the possibility to also perform object transformation while coping.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜