Why not use boxed primitives and the Object... ctor?
e.g.
new Values( "string", 1.5, 3423423423L);
On Wed, Dec 18, 2013 at 5:32 PM, Adrian Mocanu <[email protected]>wrote:
> Thanks
>
> A second pair of eyes helps J
>
>
>
> I wonder why string.toLong didn’t work ..
>
>
>
> *From:* Jon Logan [mailto:[email protected]]
> *Sent:* December-18-13 5:30 PM
> *To:* [email protected]
> *Subject:* Re: emitting various types - how to send long as string and
> unmarshal into long
>
>
>
>
> http://stackoverflow.com/questions/7693324/converting-string-to-long-in-java
>
>
>
> On Wed, Dec 18, 2013 at 5:25 PM, Adrian Mocanu <[email protected]>
> wrote:
>
> Hi
>
> I have a quick question about sending data of different types from a spout.
>
>
>
> I need to emit a string, double and long from a spout (all at once as a
> tuple).
>
> Unfortunately Values c’tor takes arguments of the same type so I decided
> to convert all of these to Strings.
>
>
>
> _collector.emit(new Values(myNameAsString, myDouble.toString,
> myLong.toString ))
>
>
>
> When the tuple is received in the bolt it cannot convert the long back
> into a long.
>
>
>
> java.lang.ClassCastException: java.lang.String cannot be cast to
> java.lang.Long
>
>
>
> I looked at the value and it is a valid long: 61345076523000
>
> The bolt code that does the str2int conversion is *val
> tupleTimestampAsLong: Long= tuple.getString(2).toLong*
>
>
>
> The question, how to emit multiple values of different types from
> spout/bolt at once? (or at least how to convert a string into a long).
>
>
>
> Thanks a lot!
>
> -Adrian
>
>
>
>
>