Skip to content

Commit c1145da

Browse files
committed
Fixed TrackAudioAnalysis serialization for arrays
1 parent aa56a1b commit c1145da

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

src/main/java/com/json/JSONArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ public JSONObject getModifiedJSONObject(int index) throws JSONException {
648648
} else if (object instanceof Boolean) {
649649
return new JSONObject(String.format("{\"value\": %b}", object));
650650
} else if (object instanceof Double) {
651-
return new JSONObject(String.format("{\"value\": %d}", object));
651+
return new JSONObject(String.format("{\"value\": %f}", object));
652652
} else if (object instanceof Integer) {
653653
return new JSONObject(String.format("{\"value\": %d}", object));
654654
} else {

src/main/java/com/spotify/objects/SpotifySerializer.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,6 @@ private <E extends Serializable> E serializeField(Class<E> componentType, JSONOb
115115

116116
@SuppressWarnings("unchecked")
117117
private <E extends Serializable> E[] createArray(Class<E> cls, JSONArray jsonArray) {
118-
if (cls.isPrimitive()) {
119-
if (cls.equals(int.class))
120-
cls = (Class<E>) Integer.class;
121-
else if (cls.equals(boolean.class))
122-
cls = (Class<E>) Boolean.class;
123-
else if (cls.equals(double.class))
124-
cls = (Class<E>) Double.class;
125-
else
126-
return null;
127-
}
128118
E[] array = (E[]) Array.newInstance(cls, jsonArray.length());
129119
for (int i = 0; i < array.length; i++)
130120
array[i] = this.serializeField(cls, jsonArray.getModifiedJSONObject(i), "value");

src/main/java/com/spotify/objects/tracks/TrackAudioAnalysis.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
import com.spotify.objects.tracks.analysis.*;
66
import lombok.Getter;
77
import lombok.Setter;
8-
import lombok.ToString;
98

109

1110
@Getter
1211
@Setter
13-
@ToString
1412
public class TrackAudioAnalysis implements SpotifyObject {
1513

1614

@@ -35,4 +33,16 @@ public class TrackAudioAnalysis implements SpotifyObject {
3533
@SpotifyField
3634
private AudioTatum[] tatums;
3735

36+
@Override
37+
public String toString() {
38+
return "TrackAudioAnalysis{" +
39+
"meta=" + meta +
40+
", track=" + track +
41+
", bars=" + bars.length +
42+
", beats=" + beats.length +
43+
", sections=" + sections.length +
44+
", segments=" + segments[0] +
45+
", tatums=" + tatums.length +
46+
'}';
47+
}
3848
}

src/main/java/com/spotify/objects/tracks/analysis/AudioSegment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import com.spotify.objects.SpotifyOptional;
66
import lombok.Getter;
77
import lombok.Setter;
8+
import lombok.ToString;
89

910
@Getter
1011
@Setter
12+
@ToString
1113
@SpotifyOptional
1214
public class AudioSegment implements SpotifyObject {
1315

@@ -34,9 +36,9 @@ public class AudioSegment implements SpotifyObject {
3436
private double loudnessEnd;
3537

3638
@SpotifyField
37-
private double[] pitches;
39+
private Double[] pitches;
3840

3941
@SpotifyField
40-
private double[] timbre;
42+
private Double[] timbre;
4143

4244
}

0 commit comments

Comments
 (0)