mirror of
https://github.com/corda/corda.git
synced 2025-02-21 01:42:24 +00:00
Merge pull request #1042 from corda/carpenterBeans
Fix toString generated method that breaks Introspection for BEANS
This commit is contained in:
commit
e48c1c1689
@ -216,7 +216,7 @@ class ClassCarpenter {
|
||||
* Generate bytecode for the given schema and load into the JVM. The returned class object can be used to
|
||||
* construct instances of the generated class.
|
||||
*
|
||||
* @throws DuplicateName if the schema's name is already taken in this namespace (you can create a new ClassCarpenter if you're OK with ambiguous names)
|
||||
* @throws DuplicateNameException if the schema's name is already taken in this namespace (you can create a new ClassCarpenter if you're OK with ambiguous names)
|
||||
*/
|
||||
fun build(schema: Schema): Class<*> {
|
||||
validateSchema(schema)
|
||||
@ -291,7 +291,7 @@ class ClassCarpenter {
|
||||
|
||||
private fun ClassWriter.generateToString(schema: Schema) {
|
||||
val toStringHelper = "com/google/common/base/MoreObjects\$ToStringHelper"
|
||||
with(visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", "", null)) {
|
||||
with(visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null)) {
|
||||
visitCode()
|
||||
// com.google.common.base.MoreObjects.toStringHelper("TypeName")
|
||||
visitLdcInsn(schema.name.split('.').last())
|
||||
|
@ -1,12 +1,11 @@
|
||||
package net.corda.core.serialization.carpenter
|
||||
|
||||
|
||||
import org.junit.Test
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Method
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
import java.beans.Introspector
|
||||
import kotlin.test.assertNotEquals
|
||||
|
||||
class ClassCarpenterTest {
|
||||
interface DummyInterface {
|
||||
@ -491,4 +490,17 @@ class ClassCarpenterTest {
|
||||
assertEquals (javax.annotation.Nonnull::class.java, clazz.getMethod("getB").annotations[0].annotationClass.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun beanTest() {
|
||||
val schema = ClassCarpenter.ClassSchema(
|
||||
"pantsPantsPants",
|
||||
mapOf("a" to ClassCarpenter.NonNullableField(Integer::class.java)))
|
||||
val clazz = cc.build(schema)
|
||||
val descriptors = Introspector.getBeanInfo(clazz).propertyDescriptors
|
||||
|
||||
assertEquals(2, descriptors.size)
|
||||
assertNotEquals(null, descriptors.find { it.name == "a" })
|
||||
assertNotEquals(null, descriptors.find { it.name == "class" })
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user