Skip to content

Object not serializing ok #496

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

Merged
merged 2 commits into from
Jan 19, 2021
Merged
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 @@ -187,10 +187,11 @@ object BeanIntrospector {
//create properties for all appropriate fields
val fields = for {
cls <- hierarchy
classW = ClassW(cls)
field <- cls.getDeclaredFields
name = maybePrivateName(field)
if !name.contains('$')
if (isScalaCaseObject(cls) || isAcceptableField(field))
if (classW.isScalaObject || isScalaCaseObject(cls) || isAcceptableField(field))
beanGetter = findBeanGetter(cls, name)
beanSetter = findBeanSetter(cls, name)
} yield PropertyDescriptor(name, findConstructorParam(hierarchy.head, name), Some(field), findGetter(cls, name), findSetter(cls, name), beanGetter, beanSetter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object ScalaAnnotationIntrospector extends NopAnnotationIntrospector with ValueI
private [this] val _descriptorCache = new LRUMap[ClassKey, BeanDescriptor](16, 100)

private def _descriptorFor(clz: Class[_]): Option[BeanDescriptor] = {
if (clz.hasSignature || clz.extendsScalaClass) {
if (clz.extendsScalaClass || clz.hasSignature) {
val key = new ClassKey(clz)
Option(_descriptorCache.get(key)) match {
case Some(result) => Some(result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.fasterxml.jackson.module.scala.util

import scala.language.implicitConversions
import scala.reflect.{ScalaLongSignature, ScalaSignature}
import scala.util.Try

trait ClassW extends PimpedType[Class[_]] {

def extendsScalaClass: Boolean = {
ClassW.productClass.isAssignableFrom(value)
ClassW.productClass.isAssignableFrom(value) || isScalaObject
}

def hasSignature: Boolean = {
Expand All @@ -19,6 +20,10 @@ trait ClassW extends PimpedType[Class[_]] {
}
hasSigHelper(value)
}

def isScalaObject: Boolean = {
Try(value.getField("MODULE$")).isSuccess
}
}

object ClassW {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ObjectSerializerTest extends SerializerTest {
import ObjectSerializerTest._
def module = DefaultScalaModule

"An ObjectMapper with the DefaultScalaModule" should "serialize an object as a bean" ignore {
"An ObjectMapper with the DefaultScalaModule" should "serialize an object as a bean" in {
serialize(ObjectWithoutJsonProperty) should (
equal ("""{"name":"name1","value":"value1"}""") or
equal ("""{"value":"value1","name":"name1"}""")
Expand Down