Skip to content

Interfaces may have non-abstract methods (since java8) #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public BeanBuilder implement(boolean failOnUnrecognized)
// First: find all supertypes:
implTypes.add(_type);
BeanUtil.findSuperTypes(_type, Object.class, implTypes);
final boolean hasConcrete = !_type.isInterface();


for (JavaType impl : implTypes) {
TypeResolutionContext ctxt = buildTypeContext(impl);

Expand Down Expand Up @@ -109,7 +108,7 @@ public BeanBuilder implement(boolean failOnUnrecognized)
continue;
}
// [module-mrbean#11]: try to support overloaded methods
if (hasConcrete && hasConcreteOverride(m, _type)) {
if (hasConcreteOverride(m, _type)) {
continue;
}
if (failOnUnrecognized) {
Expand All @@ -126,7 +125,7 @@ public BeanBuilder implement(boolean failOnUnrecognized)
/**
* Method that generates byte code for class that implements abstract
* types requested so far.
*
*
* @param className Fully-qualified name of the class to generate
* @return Byte code Class instance built by this builder
*/
Expand Down Expand Up @@ -171,7 +170,7 @@ public byte[] build(String className)
/**
* Helper method used to detect if an abstract method found in a base class
* may actually be implemented in a (more) concrete sub-class.
*
*
* @since 2.4
*/
protected boolean hasConcreteOverride(Method m0, JavaType implementedType)
Expand All @@ -191,7 +190,7 @@ protected boolean hasConcreteOverride(Method m0, JavaType implementedType)
}
return false;
}

protected String getPropertyName(String methodName)
{
int prefixLen = methodName.startsWith("is") ? 2 : 3;
Expand All @@ -215,7 +214,7 @@ protected void addGetter(TypeResolutionContext ctxt, Method m)
POJOProperty prop = findProperty(ctxt, getPropertyName(m.getName()));
// only set if not yet set; we start with super class:
if (prop.getGetter() == null) {
prop.setGetter(m);
prop.setGetter(m);
}
}

Expand All @@ -236,13 +235,13 @@ protected POJOProperty findProperty(TypeResolutionContext ctxt, String propName)
}
return prop;
}

protected final static boolean returnsBoolean(Method m)
{
Class<?> rt = m.getReturnType();
return (rt == Boolean.class || rt == Boolean.TYPE);
}

/*
/**********************************************************
/* Internal methods, bytecode generation
Expand Down Expand Up @@ -290,7 +289,7 @@ private DynamicType.Builder<?> createSetter(DynamicType.Builder<?> builder,
/* Internal methods, other
/**********************************************************
*/

protected String decap(String name) {
char c = name.charAt(0);
if (name.length() > 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.fasterxml.jackson.module.mrbean;

import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class TestDefaultMethods
extends BaseTest {

public interface HasId {
long id();
}

public interface HasLeguminousId extends HasId {
long getId();
default long id() { return getId(); }
}

public void testMaterializedDefaultMethod() throws IOException {
final ObjectMapper mapper = newMrBeanMapper();

final String input = "{\"id\": 0}";

final HasLeguminousId bean = mapper.readValue(input, HasLeguminousId.class);

assertEquals(bean.getId(), 0L);
assertEquals(bean.id(), 0L); // shouldn't be implemented by mrbean

}

}