question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PropertyNotFoundException if source object has no constructor with a parameter for the property not found

See original GitHub issue

When trying to convert from the following class(es):

public class XOrderSearchResultRecordType {
    protected AdsType ads;
    //getter, setter
}

...

public class AdsType {
    protected List<XAdRecord> xAdRecord;
    //getter, setter

Using the following configuration:

    public void configure(MapperFactory factory) {
        factory .classMap(XOrderSearchResultRecordType.class, Target.class)
                .field("ads.xAdRecord", "targetField").register();
    }
}

I get a PropertyNotFoundException on “xAdRecord”. Curiously, specifying the name of the field as XAdRecord (notice the capital X) makes Orika work. Also, adding a constructor to AdsType above with xAdRecord as a parameter will make Orika work (happens in PropertyResolver.getProperty(…) on line 706). Stacktrace:

Caused by: ma.glasnost.orika.MappingException: ClassMapBuilder.map(XOrderSearchResultRecordType, AdOrder).field('ads.xAdRecord', 'placement'): Error: could not resolve nested property [ads.xAdRecord] on XOrderSearchResultRecordType, because xAdRecord does not belong to AdsType
	at ma.glasnost.orika.metadata.ClassMapBuilder.fieldMap(ClassMapBuilder.java:338)
	at ma.glasnost.orika.metadata.ClassMapBuilder.fieldMap(ClassMapBuilder.java:311)
	at ma.glasnost.orika.metadata.ClassMapBuilder.field(ClassMapBuilder.java:249)
	at net.persgroep.adhub.converter.XOrderSearchResultRecordTypeMappingConfigurer.configure(XOrderSearchResultRecordTypeMappingConfigurer.java:18)
	at net.persgroep.adhub.converter.OrikaModelMapper.configureNewMapperFacade(OrikaModelMapper.java:51)
	at net.persgroep.adhub.converter.OrikaModelMapper.setApplicationContext(OrikaModelMapper.java:78)
	at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:121)
	at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:97)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
	... 74 more
Caused by: ma.glasnost.orika.PropertyNotFoundException: could not resolve nested property [ads.xAdRecord] on XOrderSearchResultRecordType, because xAdRecord does not belong to AdsType
	at ma.glasnost.orika.property.PropertyResolver.getNestedProperty(PropertyResolver.java:500)
	at ma.glasnost.orika.property.PropertyResolver.getProperty(PropertyResolver.java:676)
	at ma.glasnost.orika.property.PropertyResolver.getProperty(PropertyResolver.java:634)
	at ma.glasnost.orika.metadata.ClassMapBuilder.resolveProperty(ClassMapBuilder.java:879)
	at ma.glasnost.orika.metadata.FieldMapBuilder.<init>(FieldMapBuilder.java:78)
	at ma.glasnost.orika.metadata.FieldMapBuilder.<init>(FieldMapBuilder.java:61)
	at ma.glasnost.orika.metadata.ClassMapBuilder.fieldMap(ClassMapBuilder.java:328)
	... 84 more

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
rubin55commented, Sep 12, 2017

Argh… from the JavaBeans 1.01 spec document, section 8.8: capitalization of inferred names:

"When we use design patterns to infer a property or event name, we need to decide what rules to follow for capitalizing the inferred name. If we extract the name from the middle of a normal mixedCase style Java name then the name will, by default, begin with a capital letter. Java programmers are accustomed to having normal identifiers start with lower case letters. Vigorous reviewer input has convinced us that we should follow this same conventional rule for property and event names.

Thus when we extract a property or event name from the middle of an existing Java name, we normally convert the first character to lower case. However to support the occasional use of all upper-case names, we check if the first two characters of the name are both upper case and if so leave it alone. So for example, “FooBah” becomes “fooBah” “Z” becomes “z” “URL” becomes “URL”

We provide a method Introspector.decapitalize which implements this conversion rule."

I consider this is a bug in the specification (which dates from '97), but I have no illusion that that will ever be fixed… Alas, maybe someone else will run into this issue and bump into this ticket. I hope the above clarifies why capitalization of a field might or might not happen.

1reaction
elaatificommented, Sep 13, 2017

We’ve introduced RegexPropertyResolver to support your own convention: https://orika-mapper.github.io/orika-docs/extensibility.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

PropertyNotFoundException: Property 'X' not found on type X
seems like issue with below line in Jsp page. history will just to point plain String historyList and not your collection object.
Read more >
javax.el Class PropertyNotFoundException - Oracle Help Center
Thrown when a property could not be found while evaluating a ValueExpression or MethodExpression . For example, this could be triggered by an...
Read more >
BeanAdapter (JGoodies Binding 2.11 API) - javadoc.io
Converts multiple Java Bean properties into ValueModels. The bean properties must be single valued properties as described by the Java Bean Specification.
Read more >
Object.create() - JavaScript - MDN Web Docs
A new object with the specified prototype object and properties. Exceptions. TypeError. Thrown if proto is neither null nor an Object .
Read more >
javax.el - Java EE API - Open Liberty
For property resolution, the property string is used to find a JavaBeans ... If the parameter types are not specified, the parameter objects...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found