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

Default conversion from and to java.util.stream.Stream [SPR-12175] #16789

Closed
spring-issuemaster opened this issue Sep 10, 2014 · 6 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Sep 10, 2014

Yujun Liang opened SPR-12175 and commented

Similar to these, but it is for Stream from Java 8,

<util:list id="myList" value-type="java.lang.String">
    <value>foo</value>
    <value>bar</value>
</util:list>
<bean id="stages" class="java.util.ArrayList">
    <constructor-arg>
        <list>
            <ref bean="stage1" />
            <ref bean="stage2" />                
        </list>
    </constructor-arg>
</bean>

Reference URL: http://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html

Referenced from: commits 91b3caf, 018adb0

0 votes, 5 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 18, 2015

Stéphane Nicoll commented

Could you please provide a bit more details about your use case. What's stage1 and stage2 exactly? Can you show the definition of those beans?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 19, 2015

Yujun Liang commented

stage1 and stage2 can be any bean which can be put into a list. Instead of putting into a list like the examples, we can choose to use Stream which comes in Java 8.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 19, 2015

Stéphane Nicoll commented

Well. That's the generic conversion mechanism, yes. It's still unclear. Do you want the stages bean to become a Stream? or are stage1 and stage2 stream instances. If that's the latter please provide an example of bean definition.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 19, 2015

Juergen Hoeller commented

So I suppose you'd like to see <util:stream> and some kind of StreamFactoryBean? I'm not quite sure that's practically useful though... since Streams are active objects, not meant to be re-accessed. So that would only really make sense with a non-singleton setup, otherwise the shared Stream instance couldn't be reused.

I'd rather expect Stream to be declared as a bean property type, but populated from a shared List or a Set or the like. The inverse is also worth considering, populating a bean property of type List/Set from a given Stream value, but only really for data binding scenarios where the incoming values aren't being reused.

So from my perspective, providing implicit conversion for such data binding scenarios would be nice. I'm just not sure that shared setup of Stream beans is a good idea, in particular once shared List/Set beans can be automatically converted to a fresh Stream for each target property that they are being bound to.

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 19, 2015

Yujun Liang commented

Yes,

<util:stream id="myStream" value-type="java.lang.String">
<value>foo</value>
<value>bar</value>
</util:stream>

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 24, 2015

Stéphane Nicoll commented

Alright, a StreamConverter is now registered in the DefaultConversionService as long as Java8 is available. You can also register it to your custom ConverterService.

Taking back your example below, it makes much more sense to keep a list for "hard-coded" elements. If you try to inject that list in a property of type Stream this will work just fine via this new converter.

We don't see the point of creating a dedicated namespace support and a StreamFactory since you can perfectly create those using the existing infrastructure.

If you have a more specific use case in mind, please let us know. You can try this in a couple of hours with the latest 4.2.0.BUILD-SNAPSHOT

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.