spray/spray-json

NullPointerException when parsing incoming request into a ByteString1C

asontha-zz opened this issue · 1 comments

keep getting a NPE when I run my tests against my route and I've traced it down to ByteString.scala:154

here is the request coming from the test:

val requestBody:String = """{ "name": "Jane", "favoriteNumber" : 42 }"""

Put("/<someRoute>?<someParameters>")
                .withHeaders(RawHeader("Authorization", "test"))
                .withEntity(ContentTypes.\`application/json\`,
                  requestBody // <-- NPE thrown here
                ) ~>
                plan.route ~>
                check {
                  assert(response.status === StatusCodes.OK)
                }

My route:

~ put {
        parameters(<SomeParameters>) {
          (<SomeParameterVariables>) =>
                entity(as[<ProtoBuffGeneratedObject>]) {
                    request =>
                      <Response Logic>
                  }
      }

My custom deserializer/serializer:

implicit val protoObj: RootJsonFormat[<ProtoBuffGeneratedObject>] = rootFormat( new RootJsonFormat[<ProtoBuffGeneratedObject>] {
    override def read(value: JsValue): <ProtoBuffGeneratedObject> = {
      val request = <ProtoBuffGeneratedObject>.newBuilder()
      JsonFormat.parser.ignoringUnknownFields().merge(value.toString(), request)
      request.build()
    }

    override def write(obj: <ProtoBuffGeneratedObject>): JsValue = {
      com.google.protobuf.util.JsonFormat.printer()
        .omittingInsignificantWhitespace()
        .print(obj).parseJson
    }
  })

implicit val errors on my side, closing as it no longer relates to the library