johnzon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Re: [johnzon] branch master updated: JOHNZON-226 use own Array.length
Date Tue, 30 Jul 2019 13:17:04 GMT
Le mar. 30 juil. 2019 à 15:05, Mark Struberg <struberg@yahoo.de.invalid> a
écrit :

> Most situations where a JSON-P impl is available you have just JSON-P-1.0.
>

I'd say it is 50-50 today, you are right for app servers, not for all other
cases which upgrade more easily.


> And this doesn't work with our Mapper. We require JSON-P-1.1 in the
> meantime.
>

This is fine, we target a single jsonp version but still a portable version.


> So this argument imo doesn't cut it.
>

It is as biased both ways Mark and this is a feature we exposed for most of
our version (think only 1 or 2 were broken in the 1.1 upgrade time) so no
reason to add another regression IMHO.


>
> LieGrue,
> strub
>
>
> > Am 30.07.2019 um 14:37 schrieb Romain Manni-Bucau <rmannibucau@gmail.com
> >:
> >
> > Le mar. 30 juil. 2019 à 14:27, Mark Struberg <struberg@yahoo.de.invalid>
> a
> > écrit :
> >
> >> Btw, I don't think Mapper and JSON-B must be independent of our jsonp
> >> impl. I cannot think of any legit use.
> >>
> >
> > You already have a jsonp impl and need it for some other vendor specific
> > stuff and want to add johnzon-mapper/jsonb - yes yes it happens, even
> > without the RI ;).
> >
> >
> >> With older EE7 servers you might have jsonp, but then we require EE8.
> But
> >> every EE8 server always also comes with JSON-B as requirement. So what
> use
> >> case do you think of?
> >>
> >
> > EE servers are out of game there as you mention but all other use cases
> are
> > not and it quickly becomes tricky to manage its deps so I'd really like
> to
> > keep that original design constraint in.
> >
> >
> >>
> >> LieGrue,
> >> strub
> >>
> >>
> >>> Am 30.07.2019 um 14:19 schrieb Mark Struberg <struberg@yahoo.de.INVALID
> >>> :
> >>>
> >>>
> >>> Will do.
> >>> LieGrue,
> >>> strub
> >>>
> >>>
> >>>> Am 29.07.2019 um 23:12 schrieb Romain Manni-Bucau <
> >> rmannibucau@gmail.com>:
> >>>>
> >>>> Hmm, this breaks the isolation between our modules - jsonp impl must
> >> stay
> >>>> switchable in mapper and jsonb modules.
> >>>>
> >>>> Can we just duplicate the class - the old shade+relocation hack is
> fine
> >> for
> >>>> me?
> >>>>
> >>>> Also, does Foo[] match Object[] or do we have some regression - think
> we
> >>>> should harness such an utility with an exhaustive test kit?
> >>>>
> >>>> Romain
> >>>>
> >>>>
> >>>> ---------- Forwarded message ---------
> >>>> De : <struberg@apache.org>
> >>>> Date: lun. 29 juil. 2019 à 23:08
> >>>> Subject: [johnzon] branch master updated: JOHNZON-226 use own
> >> Array.length
> >>>> To: commits@johnzon.apache.org <commits@johnzon.apache.org>
> >>>>
> >>>>
> >>>> This is an automated email from the ASF dual-hosted git repository.
> >>>>
> >>>> struberg pushed a commit to branch master
> >>>> in repository https://gitbox.apache.org/repos/asf/johnzon.git
> >>>>
> >>>>
> >>>> The following commit(s) were added to refs/heads/master by this push:
> >>>>   new 41e0fdc  JOHNZON-226 use own Array.length
> >>>> 41e0fdc is described below
> >>>>
> >>>> commit 41e0fdc50c59153a03e49e85afac534949ece4e6
> >>>> Author: Mark Struberg <struberg@apache.org>
> >>>> AuthorDate: Mon Jul 29 22:49:54 2019 +0200
> >>>>
> >>>>  JOHNZON-226 use own Array.length
> >>>> ---
> >>>> .../apache/johnzon/core/JsonArrayBuilderImpl.java  |  4 ++-
> >>>> .../org/apache/johnzon/core}/util/ArrayUtil.java   | 36
> >>>> +++++++++++++++++++++-
> >>>> .../org/apache/johnzon/jsonb/JohnzonJsonb.java     | 15 ++++-----
> >>>> .../java/org/apache/johnzon/mapper/Mapper.java     |  2 +-
> >>>> .../johnzon/mapper/MappingGeneratorImpl.java       | 35
> >>>> ++-------------------
> >>>> 5 files changed, 49 insertions(+), 43 deletions(-)
> >>>>
> >>>> diff --git
> >>>>
> >>
> a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayBuilderImpl.java
> >>>>
> >>
> b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayBuilderImpl.java
> >>>> index f105eaf..effd30a 100644
> >>>> ---
> >>>>
> >>
> a/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayBuilderImpl.java
> >>>> +++
> >>>>
> >>
> b/johnzon-core/src/main/java/org/apache/johnzon/core/JsonArrayBuilderImpl.java
> >>>> @@ -33,6 +33,8 @@ import java.util.Collections;
> >>>> import java.util.List;
> >>>> import java.util.Map;
> >>>>
> >>>> +import org.apache.johnzon.core.util.ArrayUtil;
> >>>> +
> >>>> class JsonArrayBuilderImpl implements JsonArrayBuilder, Serializable
{
> >>>>   private List<JsonValue> tmpList;
> >>>>   private BufferStrategy.BufferProvider<char[]> bufferProvider;
> >>>> @@ -223,7 +225,7 @@ class JsonArrayBuilderImpl implements
> >> JsonArrayBuilder,
> >>>> Serializable {
> >>>>       } else if (value instanceof Collection) {
> >>>>           add(new JsonArrayBuilderImpl(Collection.class.cast(value),
> >>>> bufferProvider).build());
> >>>>       } else if (value.getClass().isArray()) {
> >>>> -            final int length = Array.getLength(value);
> >>>> +            final int length = ArrayUtil.getArrayLength(value);
> >>>>           final Collection<Object> collection = new
> >> ArrayList<>(length);
> >>>>           for (int i = 0; i < length; i++) {
> >>>>               collection.add(Array.get(value, i));
> >>>> diff --git
> >>>>
> >>
> a/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/util/ArrayUtil.java
> >>>>
> b/johnzon-core/src/main/java/org/apache/johnzon/core/util/ArrayUtil.java
> >>>> similarity index 75%
> >>>> rename from
> >>>>
> >>
> johnzon-mapper/src/main/java/org/apache/johnzon/mapper/util/ArrayUtil.java
> >>>> rename to
> >>>> johnzon-core/src/main/java/org/apache/johnzon/core/util/ArrayUtil.java
> >>>> index a7a6c57..646c112 100644
> >>>> ---
> >>>>
> >>
> a/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/util/ArrayUtil.java
> >>>> +++
> >> b/johnzon-core/src/main/java/org/apache/johnzon/core/util/ArrayUtil.java
> >>>> @@ -14,7 +14,7 @@
> >>>> * See the License for the specific language governing permissions and
> >>>> * limitations under the License.
> >>>> */
> >>>> -package org.apache.johnzon.mapper.util;
> >>>> +package org.apache.johnzon.core.util;
> >>>>
> >>>> import java.util.AbstractList;
> >>>> import java.util.List;
> >>>> @@ -27,6 +27,40 @@ public final class ArrayUtil {
> >>>>       // utility class ct
> >>>>   }
> >>>>
> >>>> +    public static int getArrayLength(Object array) {
> >>>> +        // Note: all types of multidimensional arrays are instanceof
> >>>> Object[]
> >>>> +        if (array instanceof Object[]) {
> >>>> +            return ((Object[]) array).length;
> >>>> +        }
> >>>> +        if (array instanceof boolean[]) {
> >>>> +            return ((boolean[])array).length;
> >>>> +        }
> >>>> +        if (array instanceof byte[]) {
> >>>> +            return ((byte[])array).length;
> >>>> +        }
> >>>> +        if (array instanceof char[]) {
> >>>> +            return ((char[]) array).length;
> >>>> +        }
> >>>> +        if (array instanceof short[]) {
> >>>> +            return ((short[]) array).length;
> >>>> +        }
> >>>> +        if (array instanceof int[]) {
> >>>> +            return ((int[]) array).length;
> >>>> +        }
> >>>> +        if (array instanceof long[]) {
> >>>> +            return ((long[]) array).length;
> >>>> +        }
> >>>> +        if (array instanceof float[]) {
> >>>> +            return ((float[]) array).length;
> >>>> +        }
> >>>> +        if (array instanceof double[]) {
> >>>> +            return ((double[]) array).length;
> >>>> +        }
> >>>> +
> >>>> +        throw new IllegalArgumentException("This is not an array! "
+
> >>>> array);
> >>>> +    }
> >>>> +
> >>>> +
> >>>>   public static List<Integer> asList(final int[] vals) {
> >>>>       return new AbstractList<Integer>() {
> >>>>           @Override
> >>>> diff --git
> >>>>
> a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonJsonb.java
> >>>>
> b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonJsonb.java
> >>>> index a9adada..7965519 100644
> >>>> ---
> >> a/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonJsonb.java
> >>>> +++
> >> b/johnzon-jsonb/src/main/java/org/apache/johnzon/jsonb/JohnzonJsonb.java
> >>>> @@ -18,6 +18,7 @@
> >>>> */
> >>>> package org.apache.johnzon.jsonb;
> >>>>
> >>>> +import org.apache.johnzon.core.util.ArrayUtil;
> >>>> import org.apache.johnzon.jsonb.api.experimental.JsonbExtension;
> >>>> import org.apache.johnzon.jsonb.extension.JsonValueReader;
> >>>> import org.apache.johnzon.jsonb.extension.JsonValueWriter;
> >>>> @@ -254,43 +255,43 @@ public class JohnzonJsonb implements Jsonb,
> >>>> AutoCloseable, JsonbExtension {
> >>>>       final Class<?> componentType =
> >>>> object.getClass().getComponentType();
> >>>>       Object[] array;
> >>>>       if (int.class == componentType) {
> >>>> -            final int length = Array.getLength(object);
> >>>> +            final int length = ArrayUtil.getArrayLength(object);
> >>>>           array = new Integer[length];
> >>>>           for (int i = 0; i < length; i++) {
> >>>>               array[i] = Array.getInt(object, i);
> >>>>           }
> >>>>       } else if (double.class == componentType) {
> >>>> -            final int length = Array.getLength(object);
> >>>> +            final int length = ArrayUtil.getArrayLength(object);
> >>>>           array = new Integer[length];
> >>>>           for (int i = 0; i < length; i++) {
> >>>>               array[i] = Array.getDouble(object, i);
> >>>>           }
> >>>>       } else if (byte.class == componentType) {
> >>>> -            final int length = Array.getLength(object);
> >>>> +            final int length = ArrayUtil.getArrayLength(object);
> >>>>           array = new Integer[length];
> >>>>           for (int i = 0; i < length; i++) {
> >>>>               array[i] = Array.getByte(object, i);
> >>>>           }
> >>>>       } else if (char.class == componentType) {
> >>>> -            final int length = Array.getLength(object);
> >>>> +            final int length = ArrayUtil.getArrayLength(object);
> >>>>           array = new Integer[length];
> >>>>           for (int i = 0; i < length; i++) {
> >>>>               array[i] = Array.getChar(object, i);
> >>>>           }
> >>>>       } else if (float.class == componentType) {
> >>>> -            final int length = Array.getLength(object);
> >>>> +            final int length = ArrayUtil.getArrayLength(object);
> >>>>           array = new Integer[length];
> >>>>           for (int i = 0; i < length; i++) {
> >>>>               array[i] = Array.getFloat(object, i);
> >>>>           }
> >>>>       } else if (long.class == componentType) {
> >>>> -            final int length = Array.getLength(object);
> >>>> +            final int length = ArrayUtil.getArrayLength(object);
> >>>>           array = new Integer[length];
> >>>>           for (int i = 0; i < length; i++) {
> >>>>               array[i] = Array.getLong(object, i);
> >>>>           }
> >>>>       } else if (short.class == componentType) {
> >>>> -            final int length = Array.getLength(object);
> >>>> +            final int length = ArrayUtil.getArrayLength(object);
> >>>>           array = new Integer[length];
> >>>>           for (int i = 0; i < length; i++) {
> >>>>               array[i] = Array.getShort(object, i);
> >>>> diff --git
> >>>> a/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/Mapper.java
> >>>> b/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/Mapper.java
> >>>> index 1027fca..b95935e 100644
> >>>> ---
> a/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/Mapper.java
> >>>> +++
> b/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/Mapper.java
> >>>> @@ -53,7 +53,7 @@ import javax.json.stream.JsonGeneratorFactory;
> >>>>
> >>>> import org.apache.johnzon.mapper.internal.JsonPointerTracker;
> >>>> import org.apache.johnzon.mapper.reflection.JohnzonCollectionType;
> >>>> -import org.apache.johnzon.mapper.util.ArrayUtil;
> >>>> +import org.apache.johnzon.core.util.ArrayUtil;
> >>>>
> >>>> public class Mapper implements Closeable {
> >>>>
> >>>> diff --git
> >>>>
> >>
> a/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/MappingGeneratorImpl.java
> >>>>
> >>
> b/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/MappingGeneratorImpl.java
> >>>> index 1b4d4e8..27de775 100644
> >>>> ---
> >>>>
> >>
> a/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/MappingGeneratorImpl.java
> >>>> +++
> >>>>
> >>
> b/johnzon-mapper/src/main/java/org/apache/johnzon/mapper/MappingGeneratorImpl.java
> >>>> @@ -21,6 +21,7 @@ package org.apache.johnzon.mapper;
> >>>> import static java.util.Collections.emptyList;
> >>>>
> >>>> import org.apache.johnzon.mapper.internal.JsonPointerTracker;
> >>>> +import org.apache.johnzon.core.util.ArrayUtil;
> >>>>
> >>>> import javax.json.JsonValue;
> >>>> import javax.json.stream.JsonGenerator;
> >>>> @@ -470,7 +471,7 @@ public class MappingGeneratorImpl implements
> >>>> MappingGenerator {
> >>>>    * @param key either the attribute key or {@code null} if the array
> >>>> should be rendered without key
> >>>>    */
> >>>>   private void writeArray(Class<?> type, Adapter itemConverter,
String
> >>>> key, Object arrayValue, Collection<String> ignoredProperties,
> >>>> JsonPointerTracker jsonPointer) {
> >>>> -        final int length = getArrayLength(arrayValue);
> >>>> +        final int length = ArrayUtil.getArrayLength(arrayValue);
> >>>>       if (length == 0 && config.isSkipEmptyArray()) {
> >>>>           return;
> >>>>       }
> >>>> @@ -582,38 +583,6 @@ public class MappingGeneratorImpl implements
> >>>> MappingGenerator {
> >>>>       generator.writeEnd();
> >>>>   }
> >>>>
> >>>> -    private int getArrayLength(Object array) {
> >>>> -        // Note: all types of multidimensional arrays are instanceof
> >>>> Object[]
> >>>> -        if (array instanceof Object[]) {
> >>>> -            return ((Object[]) array).length;
> >>>> -        }
> >>>> -        if (array instanceof boolean[]) {
> >>>> -            return ((boolean[])array).length;
> >>>> -        }
> >>>> -        if (array instanceof byte[]) {
> >>>> -            return ((byte[])array).length;
> >>>> -        }
> >>>> -        if (array instanceof char[]) {
> >>>> -            return ((char[]) array).length;
> >>>> -        }
> >>>> -        if (array instanceof short[]) {
> >>>> -            return ((short[]) array).length;
> >>>> -        }
> >>>> -        if (array instanceof int[]) {
> >>>> -            return ((int[]) array).length;
> >>>> -        }
> >>>> -        if (array instanceof long[]) {
> >>>> -            return ((long[]) array).length;
> >>>> -        }
> >>>> -        if (array instanceof float[]) {
> >>>> -            return ((float[]) array).length;
> >>>> -        }
> >>>> -        if (array instanceof double[]) {
> >>>> -            return ((double[]) array).length;
> >>>> -        }
> >>>> -
> >>>> -        throw new IllegalArgumentException("This is not an array! "
+
> >>>> array);
> >>>> -    }
> >>>>
> >>>>   private void writeItem(final Object o, final Collection<String>
> >>>> ignoredProperties, JsonPointerTracker jsonPointer) {
> >>>>       if (o == null) {
> >>>
> >>
> >>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message