Skip to content

Commit

Permalink
Commit missed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
falkreon committed Jul 12, 2024
1 parent c5f0799 commit 01aeadc
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/java/blue/endless/jankson/api/Jankson.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import blue.endless.jankson.api.io.ObjectWriter;
import blue.endless.jankson.api.io.StructuredDataReader;
import blue.endless.jankson.api.io.ValueElementWriter;
import blue.endless.jankson.impl.io.pojo.ObjectStructuredDataReader;
import blue.endless.jankson.impl.io.objectreader.ObjectStructuredDataReader;


public class Jankson {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

package blue.endless.jankson.impl.io.pojo;
package blue.endless.jankson.impl.io.objectreader;

import java.lang.reflect.Array;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

package blue.endless.jankson.impl.io.pojo;
package blue.endless.jankson.impl.io.objectreader;

import java.util.Collection;
import java.util.Iterator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

package blue.endless.jankson.impl.io.pojo;
package blue.endless.jankson.impl.io.objectreader;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* MIT License
*
* Copyright (c) 2018-2024 Falkreon (Isaac Ellingson)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package blue.endless.jankson.impl.io.objectreader;

import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;

import blue.endless.jankson.api.io.StructuredData;

public class MapStructuredDataReader extends DelegatingStructuredDataReader {
private final Map<Object, Object> map;
private final Iterator<Map.Entry<Object, Object>> iterator;

@SuppressWarnings("unchecked")
public MapStructuredDataReader(Map<?, ?> map) {
this.map = (Map<Object, Object>) map;
this.iterator = this.map.entrySet().iterator();

this.prebuffer(StructuredData.OBJECT_START);
}

@Override
protected void onDelegateEmpty() throws IOException {
if (!iterator.hasNext()) {
prebuffer(StructuredData.OBJECT_END);
prebuffer(StructuredData.EOF);
return;
}

Map.Entry<Object, Object> entry = iterator.next();
prebuffer(StructuredData.objectKey(
Objects.toString(entry.getKey())
));
setDelegate(ObjectStructuredDataReader.of(entry.getValue()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

package blue.endless.jankson.impl.io.pojo;
package blue.endless.jankson.impl.io.objectreader;

import java.io.IOException;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -93,7 +93,7 @@ protected void onDelegateEmpty() throws IOException {
public static StructuredDataReader of(Object o) {
if (o.getClass().isArray()) return new ArrayStructuredDataReader(o);
if (o instanceof Collection val) return new CollectionStructuredDataReader(val);
if (o instanceof Map val) throw new UnsupportedOperationException("Maps not yet implemented.");
if (o instanceof Map val) return new MapStructuredDataReader(val);
if (PrimitiveElement.canBox(o)) return new PrimitiveStructuredDataReader(o);
return new ObjectStructuredDataReader(o);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

package blue.endless.jankson.impl.io.pojo;
package blue.endless.jankson.impl.io.objectreader;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* MIT License
*
* Copyright (c) 2018-2024 Falkreon (Isaac Ellingson)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package blue.endless.jankson.impl.io.objectreader;
2 changes: 1 addition & 1 deletion src/test/java/blue/endless/jankson/TestSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import blue.endless.jankson.api.io.StructuredDataReader;
import blue.endless.jankson.api.io.ValueElementWriter;
import blue.endless.jankson.impl.ObjectToStructuredDataPipe;
import blue.endless.jankson.impl.io.pojo.ObjectStructuredDataReader;
import blue.endless.jankson.impl.io.objectreader.ObjectStructuredDataReader;

import java.io.IOException;
import java.io.StringWriter;
Expand Down

0 comments on commit 01aeadc

Please sign in to comment.