Comments (10)
@Priyanshu-ai902 This project does not assign issues. Feel free to work on any issue that interests you.
from json-java.
I decided to change the title, as it's late for me and i made mistake in it.
According to your javadocs, this is not a desired behavior.
from json-java.
@JulWas797 JSONArray.toString() will output a JSON doc, if that is what you want. We cannot change toList() due to backwards compatibility. Can you describe what you are trying to do?
from json-java.
@JulWas797 JSONArray.toString() will output a JSON doc, if that is what you want. We cannot change toList() due to backwards compatibility. Can you describe what you are trying to do?
Thanks for responding!
What I'm trying to basically acheive is to access elements of JSONArray
using Streams API, and using .toList()
is the only option to do so.
As JSONArray
already has Iterator, i would propose to integrate Streams directly in it (I will also check what I can do, and maybe try to make PR with this).
from json-java.
Streams support proposed implementation: #768
from json-java.
Sir @stleary , What will be the expected result we want? I just started putting my steps in the open-source community. I will be glad if I can help :)
from json-java.
@stleary
I can propose a solution for this: I can make the org.json.JSONArray
to implement the java.util.List
interface and not the Iterable
directly. This way, it will have the stream()
method also all the functionality that a List
should have. Because as I see from the class code it behaves like a List
but with some minor changes.
(I have these changes ready for PR)
from json-java.
Hi @stleary i am interested in this issue
Will you assign me this issue to work on it
from json-java.
@stleary So if we can't use (for now at least) the Java 8 features we can't make the JSONArray
return a Stream
. The problem from the issue description is that when the toList()
is called, it will translate all the JSONObject
to HasMap
and the HasMap
class has the toString()
method to print the map to this format.
{data={pressure_avg=1012.3399999999999, humidity_avg=61.5, temperature_avg=12.85, pm10_avg=0.6900000000000001, pm25_avg=0.36}, school={city=DŁUGOŁĘKA, street=null, post_code=19-111, latitude=53.2753471, name=SZKOŁA PODSTAWOWA W DŁUGOŁĘCE, longitude=22.8683732}, timestamp=2023-05-19 23:56:45}
@JulWas797 As I see, the only way to iterate the "real" data inside the JSONArray
is from the Iterator
. To make an Iterable
to Stream
you can do the following:
JSONArray jArray = ...;
Iterable<Object> iterable = () -> jArray.iterator();
Stream<Object> stream = StreamSupport.stream(iterable.spliterator(), false);
from json-java.
@ZachsCoffee It was probably not a great idea to include JSONArray.toList()
in the project in the first place. The best thing to do now may be to mark it as @deprecated
with a comment explaining how someone might get the desired functionality by coding an external method with the streaming API. You can add a getAsList()
, optList()
, or a similar method if you can think of a valid use case and code it in a way that does not require Java 8.
from json-java.
Related Issues (20)
- JSONObject stack overflow HOT 4
- JSONObject.toString does not use an Enum's `toString()` but its `name()` HOT 5
- Duplicate key processing? HOT 5
- Separate Control for Type Conversion of Numbers and Booleans in XML to JSON Conversion HOT 3
- Allow type widening (eg integer to string) HOT 1
- Cleanup and merge tests HOT 1
- Performance improvement for POJO conversion into JSONObject HOT 1
- Migrating to Junit 5 HOT 7
- A0p HOT 1
- Externalize JSON Test Files
- Information is lost when converting hexadecimal value from xml to json. HOT 6
- JavaDoc warnings are present HOT 4
- JavaDoc warnings in Java 21 HOT 2
- Enhancement: Replace assetTrue with assetEquals in tests HOT 2
- Enhancement: Improve toString performance HOT 2
- Suggestion: Code Coverage Badge HOT 1
- Minor: "latest release" points not to the newest release HOT 2
- Problem with optLong, getLong when parsing JSONObject and XML HOT 3
- JSONArray converting incorrect input string to array HOT 7
- Automatically update Javadoc with GitHub Actions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-java.