@@ -0,0 +1,2747 @@
+/*%0A * Copyright (C) 2014 Kalin Maldzhanski%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.djodjo.json;%0A%0A%0Aimport java.util.Iterator;%0Aimport java.util.Map;%0A%0A%0A/**%0A * Helper class that can be used for Json Objects containing always the same type;%0A *%0A * @param %3CT%3E The type%0A */%0Apublic abstract class TypedJsonObject%3CT%3E extends JsonObjectWrapper implements Iterable%3CMap.Entry%3CString, T%3E%3E %7B%0A%0A    public T getValue(String key) throws JsonException%7B%0A        return get(getJson().get(key));%0A    %7D%0A%0A    public T optValue(String key) throws JsonException%7B%0A        return get(getJson().opt(key));%0A    %7D%0A%0A    public TypedJsonObject%3CT%3E putValue(String key, T value) throws JsonException %7B%0A        getJson().put(key, to(value));%0A        return this;%0A    %7D%0A%0A    protected abstract T get(JsonElement jsonElement);%0A    protected abstract JsonElement to(T value);%0A%0A    @Override%0A    public Iterator%3CMap.Entry%3CString, T%3E%3E iterator() %7B%0A        return new Iterator%3CMap.Entry%3CString, T%3E%3E() %7B%0A            @Override%0A            public boolean hasNext() %7B%0A                return getJson().iterator().hasNext();%0A            %7D%0A%0A            @Override%0A            public Map.Entry%3CString, T%3E next() %7B%0A                return new TypedObjectEntry(getJson().iterator().next());%0A            %7D%0A%0A            @Override%0A            public void remove() %7B%0A                getJson().iterator().remove();%0A            %7D%0A        %7D;%0A    %7D%0A%0A    public int length() %7B%0A        return getJson().length();%0A    %7D%0A%0A    final class TypedObjectEntry implements Map.Entry%3CString, T%3E %7B%0A        private final String key;%0A        private T value;%0A%0A        public TypedObjectEntry(Map.Entry%3CString, JsonElement%3E entry) %7B%0A            this.key = entry.getKey();%0A            this.value = get(entry.getValue());%0A        %7D%0A%0A        public TypedObjectEntry(String key, T value) %7B%0A            this.key = key;%0A            this.value = value;%0A        %7D%0A%0A        @Override%0A        public String getKey() %7B%0A            return key;%0A        %7D%0A%0A        @Override%0A        public T getValue() %7B%0A            return value;%0A        %7D%0A%0A        @Override%0A        public T setValue(T value) %7B%0A            T old = this.value;%0A            this.value = value;%0A            return old;%0A        %7D%0A    %7D%0A%7D%0A

add typed json object