Skip to content
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

NPE during transformation #22

Closed
loumaus opened this issue Apr 21, 2011 · 2 comments
Closed

NPE during transformation #22

loumaus opened this issue Apr 21, 2011 · 2 comments

Comments

@loumaus
Copy link

loumaus commented Apr 21, 2011

Hi there ..

am facing a NPE and actually have no idea how to fix it.

My environment:

Scala: 2.8.1
sjson: 2.8.1_0.8

The exception:
java.lang.NullPointerException
at sjson.json.JsBean$$anonfun$3.apply(JsBean.scala:287)
at sjson.json.JsBean$$anonfun$3.apply(JsBean.scala:285)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:34)
at scala.collection.mutable.ArrayOps.foreach(ArrayOps.scala:35)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:206)
at scala.collection.mutable.ArrayOps.map(ArrayOps.scala:35)
at sjson.json.JsBean$class.toJSON(JsBean.scala:285)
at sjson.json.Serializer$SJSON$.toJSON(Serializer.scala:112)
at sjson.json.Serializer$SJSON$class.out(Serializer.scala:38)
at sjson.json.Serializer$SJSON$.out(Serializer.scala:112)
at de.liventy.xfunds.ws.ResourcesUtil$class.serializeAsJSON(ProfileResource.scala:27)
at de.liventy.xfunds.ws.ShopResource.serializeAsJSON(ShopResource.scala:21)

The underlying classes:

trait ResourcesUtil {
def serializeAsJSON(obj: AnyRef): String = new String(Serializer.SJSON.out(obj))

def deserializeJSON[T](json: Array[Byte])(implicit m: Manifest[T]): AnyRef =
Serializer.SJSON.inT(m)
}

@JsonIgnoreProperties(Array("navigationcategory.sushiBarSourceCategoryId"))
class NavigationCategory {
@JsonProperty("navigationcategory.hasSubCategory") var hasSubCategory: Boolean = _
@JsonProperty("navigationcategory.navigationCategoryId") var id: Long = _
@JsonProperty("navigationcategory.overNavigationCategoryId") var overId: Long = _
@JsonProperty("navigationcategory.navigationCategoryNavisionId") var navisionId: Long = _
@JsonProperty("navigationcategory.navigationCategoryName") var name: String = _
@JsonProperty("navigationcategory.totalNumberOfProducts") var totalNumberOfProducts: Long = _

var resources:List[NavigationCategoryResource] = _

def setHasSubCategory(b:String){
hasSubCategory= if (b.equals("true")){true} else {false}
}

def setResources(jl:java.util.List[NavigationCategoryResource]){
resources = jl.toList
}
}

class NavigationCategoryResource{
@JsonProperty("resource.fileUrl") var fileUrl: String = _
@JsonProperty("resource.link") var link: String = _
@JsonProperty("resource.logicalCode") var logicalCode: String = _

}

Any hint or help is appreciated ...

@debasishg
Copy link
Owner

Thanks for using sjson. I will have a look at the earliest and let u know. I don't have the source code right now .. give me some time .. will get back.

@debasishg
Copy link
Owner

I think the reason you're getting NPE is because you missed out specifying @BeanInfo in the classes. I changed your class by doing the same and also changing the annotation @JsonProperty to what sjson supports (you had specified @JsonProperty, which is possibly something you implemented. Anyway here's the stuff that runs fine ..

@BeanInfo
class NavigationCategory {
@JsonProperty("navigationcategory.hasSubCategory") var hasSubCategory: Boolean = _
@JsonProperty("navigationcategory.navigationCategoryId") var id: Long = _
@JsonProperty("navigationcategory.overNavigationCategoryId") var overId: Long = _
@JsonProperty("navigationcategory.navigationCategoryNavisionId") var navisionId: Long = _
@JsonProperty("navigationcategory.navigationCategoryName") var name: String = _
@JsonProperty("navigationcategory.totalNumberOfProducts") var totalNumberOfProducts: Long = _

var resources:List[NavigationCategoryResource] = _

def setHasSubCategory(b:String){
  hasSubCategory= if (b.equals("true")){true} else {false}
}

// def setResources(jl:java.util.List[NavigationCategoryResource]){
def setResources(jl:List[NavigationCategoryResource]){
  resources = jl
}

}

@BeanInfo
class NavigationCategoryResource {
@JsonProperty("resource.fileUrl") var fileUrl: String = _
@JsonProperty("resource.link") var link: String = _
@JsonProperty("resource.logicalCode") var logicalCode: String = _
}

and the test case ..

val r = new NavigationCategoryResource
r.fileUrl = "http://google.com"
r.link = "link"
r.logicalCode = "logical_code"

val s = new NavigationCategory
s.setHasSubCategory("false")
s.setResources(List(r))
println(s)
val out = new String(serializer.out(s))
println(out)
val in = serializer.inNavigationCategory
println(in)

let me know if this works .. I am closing the issue right now. Will reopen is required ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants