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

Fix spray-json unmarshalling #699

Merged
merged 4 commits into from
Jan 2, 2017

Conversation

jrudolph
Copy link
Member

Changes:

  • upgrade to spray-json 1.3.3 (which has working 4-byte UTF-8 character decoding for all Scala versions)
  • use new IndexedBytesParserInput to avoid copied code from spray-json
  • refactor unmarshallers to base all on a single implementation
  • fix tests to actually test more kinds of UTF-8 characters

Fixes #691.

@akka-ci akka-ci added the validating PR that is currently being validated by Jenkins label Dec 30, 2016
@akka-ci
Copy link

akka-ci commented Dec 30, 2016

Test FAILed.

@jrudolph jrudolph force-pushed the jr/w/691-spray-json-UTF-8-decoding branch from 948d7c4 to dd3c33f Compare December 30, 2016 14:49
@akka-ci akka-ci added the validating PR that is currently being validated by Jenkins label Dec 30, 2016
@jrudolph
Copy link
Member Author

Needed to mima around some things... ;)

@akka-ci akka-ci added tested PR that was successfully built and tested by Jenkins and removed validating PR that is currently being validated by Jenkins labels Dec 30, 2016
@akka-ci
Copy link

akka-ci commented Dec 30, 2016

Test PASSed.

@@ -70,6 +28,7 @@ final class SprayJsonByteStringParserInput(bytes: ByteString) extends DefaultPar
StandardCharsets.UTF_8.decode(bytes.slice(start, end).asByteBuffer).array()
}

@deprecated("Not needed any more. Should have been private.", "10.0.2")
object SprayJsonByteStringParserInput {
private final val EOI = '\uFFFF'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to remove the private members?

implicit def sprayJsonByteStringUnmarshaller[T](implicit reader: RootJsonReader[T]): FromByteStringUnmarshaller[T] =
implicit def sprayJsValueUnmarshaller: FromEntityUnmarshaller[JsValue] =
Unmarshaller.byteStringUnmarshaller
.forContentTypes(`application/json`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly this forces the content type to avoid errors but keeps the charset attribute, which the old code explicitly handled. With the move to use SprayJsonByteStringParserInput is this explicit decoding no longer needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content type json includes it being UTF-8 actually so this forces that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(as according to the JSON spec)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do we need a test that it will re-encode the original content? I'm mainly concerned that this could introduce a regression in the sense that the original special case must have been put in place for a reason.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to http://www.iana.org/assignments/media-types/application/json adding charset parameter should have no effect:

Note:  No "charset" parameter is defined for this registration.
   Adding one really has no effect on compliant recipients.

So, yes, we might introduce a regression for people relying on non-standard behavior. In reality, it might not be a big deal because almost everyone seems to be on UTF-8 nowadays. It is still possible to create a custom unmarshaller if you need to deal with non-standard data. If it turns out that this is a pain point for lots of people we can still revert to more relaxed behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification.

} else EOI
}
}
@deprecated("Will be made private.", "10.0.2")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good 👍

* Deprecated in favor of [[unmarshal]].
*/
@deprecated("Use unmarshal instead.", "10.0.2")
def unmarshall(a: A, ec: ExecutionContext, mat: Materializer): CompletionStage[B] = unmarshal(a, ec, mat)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol ok :)

@@ -57,7 +57,7 @@ object Dependencies {
val alpnApi = "org.eclipse.jetty.alpn" % "alpn-api" % "1.1.3.v20160715" // ApacheV2

object Docs {
val sprayJson = "io.spray" %% "spray-json" % "1.3.2" % "test"
val sprayJson = Compile.sprayJson % "test"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align the "test" please?

Copy link
Member

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a minor comment but LGTM in general 👍

Changes:
 * upgrade to spray-json 1.3.3 (which has working 4-byte UTF-8 character
   decoding for all Scala versions)
 * use new IndexedBytesParserInput to avoid copied code from spray-json
 * refactor unmarshallers to base all on a single implementation
 * fix tests to actually test more kinds of UTF-8 characters
@jrudolph jrudolph force-pushed the jr/w/691-spray-json-UTF-8-decoding branch from dd3c33f to d67300e Compare January 2, 2017 14:43
@akka-ci akka-ci added validating PR that is currently being validated by Jenkins tested PR that was successfully built and tested by Jenkins and removed tested PR that was successfully built and tested by Jenkins validating PR that is currently being validated by Jenkins labels Jan 2, 2017
@akka-ci
Copy link

akka-ci commented Jan 2, 2017

Test PASSed.

@jrudolph jrudolph merged commit 0b227d7 into akka:master Jan 2, 2017
@jrudolph jrudolph deleted the jr/w/691-spray-json-UTF-8-decoding branch February 20, 2017 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tested PR that was successfully built and tested by Jenkins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Difference detected between akka-http_2.11-10.0.1 and akka-http_2.12-10.0.1
4 participants