Good to know! I will have case classes anyway.

On Mon, Nov 21, 2016 at 9:55 AM, Konrad Malawski <
konrad.malaw...@typesafe.com> wrote:

> You have sadly bumped into an weird edge case here, this API was designed
> mostly for streaming case classes in mind,
> as streaming primitives may be a nice hello world but rarely is the thing
> one wants I think...
>
> To workaround the limitation you can provide an explicit marshaller that
> exposes the String as application/json value:
>
> implicit val stringFormat = Marshaller[String, ByteString] { ec ⇒ s ⇒
>   Future.successful {
>     List(Marshalling.WithFixedContentType(ContentTypes.`application/json`, () 
> ⇒
>       ByteString("\"" + s + "\"")) // "raw string" to be rendered as json 
> element in our stream must be enclosed by ""
>     )
>   }
> }
>
>
> with this it'll work. The issue is that while we do provide marshallers
> for String, they're of type text/plain, which the streaming infrastructure
> looks at and decides "oh, I can't use that, I'm supposed to stream json".
> Eventually it runs out of options and does not marshall anything...
>
> I've made a PR which makes this an explicit error now, and we'll discuss
> in the team how to provide better compile time safety for this.
> Please track the issue 424 for more discussion on this.
>
>
> PS: For case classes, e.g. using spray-json or any json library to
> generate the marshallers (see akka-http-json) it'll work properly.
>
>
> On Mon, Nov 21, 2016 at 3:47 PM, Konrad Malawski <
> konrad.malaw...@typesafe.com> wrote:
>
>> Thanks for reporting Richard - seems there's a bug somewhere, I'm looking
>> into it.
>> Seems it doesn't compose nicely with existing predefined primitive
>> marshallers (like String here), if it was wrapped in a type (say
>> Thing("One") then it works, which is what all our tests were doing).
>>
>> Please track this issue to be informed about progress:
>> https://github.com/akka/akka-http/issues/424
>>
>> --
>> Konrad
>>
>> On Sat, Nov 19, 2016 at 1:55 AM, Richard Rodseth <rrods...@gmail.com>
>> wrote:
>>
>>> Trying this out for the first time. I get a 200 OK but empty body.
>>>
>>>     val eventsRoute = path("events") {
>>>
>>>       get {
>>>
>>>         //val results: List[String] = List("One", "Two", "Three")
>>>
>>>         val results: Source[String, NotUsed] = Source(List("One", "Two",
>>> "Three"))
>>>
>>>         complete(results)
>>>
>>>       }
>>>
>>>     }
>>>
>>> The actor that defines the Route mixes in a trait with:
>>>
>>>   val start = ByteString.empty
>>>
>>>   val sep = ByteString("\n")
>>>
>>>   val end = ByteString.empty
>>>
>>>   implicit val jsonStreamingSupport = EntityStreamingSupport.json()
>>>
>>>     .withFramingRenderer(Flow[ByteString].intersperse(start, sep, end))
>>>
>>>
>>> --
>>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>>> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/c
>>> urrent/additional/faq.html
>>> >>>>>>>>>> Search the archives: https://groups.google.com/grou
>>> p/akka-user
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "Akka User List" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to akka-user+unsubscr...@googlegroups.com.
>>> To post to this group, send email to akka-user@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/akka-user.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Cheers,
>> Konrad 'ktoso' Malawski
>> Akka <http://akka.io/> @ Typesafe <http://typesafe.com/>
>>
>
>
>
> --
> Cheers,
> Konrad 'ktoso' Malawski
> Akka <http://akka.io/> @ Typesafe <http://typesafe.com/>
>
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/
> current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to akka-user+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to