├── library ├── .gitignore ├── src │ ├── main │ │ └── java │ │ │ └── ru │ │ │ └── noties │ │ │ └── flatten │ │ │ ├── Flattened.java │ │ │ ├── Flatten.java │ │ │ ├── FlattenedImpl.java │ │ │ └── FlattenJsonDeserializer.java │ └── test │ │ └── java │ │ └── ru │ │ └── noties │ │ └── flatten │ │ └── FlattenTest.java └── build.gradle ├── settings.gradle ├── .gitignore ├── gradle_maven_jar_publish.gradle ├── README.md └── LICENSE /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':library' 2 | -------------------------------------------------------------------------------- /library/src/main/java/ru/noties/flatten/Flattened.java: -------------------------------------------------------------------------------- 1 | package ru.noties.flatten; 2 | 3 | /** 4 | * Created by Dimitry Ivanov on 29.10.2015. 5 | */ 6 | public interface Flattened { 7 | 8 | T get(); 9 | boolean hasValue(); 10 | } 11 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | 3 | dependencies { 4 | 5 | compile 'com.google.code.gson:gson:2.4' 6 | 7 | testCompile 'junit:junit:4.12' 8 | } 9 | 10 | if (project.hasProperty('POM_NAME')) { 11 | apply from: '../gradle_maven_jar_publish.gradle' 12 | } -------------------------------------------------------------------------------- /library/src/main/java/ru/noties/flatten/Flatten.java: -------------------------------------------------------------------------------- 1 | package ru.noties.flatten; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * The pattern is simple, delimit with `::` 10 | * Created by Dimitry Ivanov on 29.10.2015. 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target(ElementType.FIELD) 14 | public @interface Flatten { 15 | String value(); 16 | } 17 | -------------------------------------------------------------------------------- /library/src/main/java/ru/noties/flatten/FlattenedImpl.java: -------------------------------------------------------------------------------- 1 | package ru.noties.flatten; 2 | 3 | /** 4 | * Created by Dimitry Ivanov on 29.10.2015. 5 | */ 6 | class FlattenedImpl implements Flattened { 7 | 8 | static final FlattenedImpl EMPTY = new FlattenedImpl<>(null); 9 | 10 | final T value; 11 | 12 | public FlattenedImpl(T value) { 13 | this.value = value; 14 | } 15 | 16 | @Override 17 | public T get() { 18 | return value; 19 | } 20 | 21 | @Override 22 | public boolean hasValue() { 23 | return value != null; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea 4 | .DS_Store 5 | 6 | /gradle 7 | gradlew 8 | gradlew.bat 9 | 10 | **/build 11 | 12 | *.iml 13 | 14 | # built application files 15 | *.apk 16 | *.ap_ 17 | 18 | # files for the dex VM 19 | *.dex 20 | 21 | # Java class files 22 | *.class 23 | 24 | # generated files 25 | bin/ 26 | gen/ 27 | build/ 28 | 29 | # Local configuration file (sdk path, etc) 30 | local.properties 31 | 32 | # gradle properties with signing config 33 | gradle.properties 34 | 35 | # Project configuration file (target-sdk-version) 36 | .DS_Store 37 | project.properties 38 | out 39 | 40 | # Eclipse project files 41 | .classpath 42 | .project 43 | 44 | # Proguard folder generated by Eclipse 45 | proguard/ 46 | 47 | # Intellij project files 48 | *.iml 49 | *.ipr 50 | *.iws 51 | .idea/ 52 | .gradle/ -------------------------------------------------------------------------------- /gradle_maven_jar_publish.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven' 2 | apply plugin: 'signing' 3 | 4 | def isReleaseBuild() { 5 | return VERSION_NAME.contains("SNAPSHOT") == false 6 | } 7 | 8 | def getReleaseRepositoryUrl() { 9 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL 10 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 11 | } 12 | 13 | def getSnapshotRepositoryUrl() { 14 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL 15 | : "https://oss.sonatype.org/content/repositories/snapshots/" 16 | } 17 | 18 | def getRepositoryUsername() { 19 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" 20 | } 21 | 22 | def getRepositoryPassword() { 23 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" 24 | } 25 | 26 | afterEvaluate { project -> 27 | uploadArchives { 28 | repositories { 29 | mavenDeployer { 30 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 31 | 32 | pom.groupId = GROUP 33 | pom.artifactId = POM_ARTIFACT_ID 34 | pom.version = VERSION_NAME 35 | 36 | repository(url: getReleaseRepositoryUrl()) { 37 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 38 | } 39 | snapshotRepository(url: getSnapshotRepositoryUrl()) { 40 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 41 | } 42 | 43 | pom.project { 44 | name POM_NAME 45 | packaging POM_PACKAGING 46 | description POM_DESCRIPTION 47 | url POM_URL 48 | 49 | scm { 50 | url POM_SCM_URL 51 | connection POM_SCM_CONNECTION 52 | developerConnection POM_SCM_DEV_CONNECTION 53 | } 54 | 55 | licenses { 56 | license { 57 | name POM_LICENCE_NAME 58 | url POM_LICENCE_URL 59 | distribution POM_LICENCE_DIST 60 | } 61 | } 62 | 63 | developers { 64 | developer { 65 | id POM_DEVELOPER_ID 66 | name POM_DEVELOPER_NAME 67 | } 68 | } 69 | } 70 | } 71 | } 72 | } 73 | 74 | signing { 75 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 76 | sign configurations.archives 77 | } 78 | 79 | task javadocs(type: Javadoc) { 80 | source = sourceSets.main.java.srcDirs 81 | classpath += project.files() 82 | } 83 | 84 | task javadocJar(type: Jar, dependsOn: javadocs) { 85 | classifier = 'javadoc' 86 | from javadoc.destinationDir 87 | } 88 | 89 | task sourcesJar(type: Jar, dependsOn: classes) { 90 | classifier = 'sources' 91 | from sourceSets.main.allSource 92 | } 93 | 94 | artifacts { 95 | archives sourcesJar 96 | archives javadocJar 97 | } 98 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flatten 2 | [![Maven Central](https://img.shields.io/maven-central/v/ru.noties/flatten.svg)](http://search.maven.org/#search|ga|1|g%3A%22ru.noties%22%20AND%20a%3A%22flatten%22) 3 | 4 | Flatten json response with this simple library (for those who uses Gson for json deserialization). 5 | 6 | ## Use case 7 | 8 | Given a json: 9 | ```json 10 | { 11 | "first": { 12 | "second": { 13 | "third": { 14 | "forth": { 15 | "fifth": { 16 | "hello_here_i_am": true 17 | } 18 | } 19 | } 20 | } 21 | } 22 | } 23 | ``` 24 | 25 | ### The *old* way 26 | Mostly one would end up with a bunch of inner classes: 27 | ```java 28 | public static class Response { 29 | First first; 30 | } 31 | 32 | private static class First { 33 | Second second; 34 | } 35 | 36 | private static class Second { 37 | Third third; 38 | } 39 | 40 | private static class Third { 41 | Forth forth; 42 | } 43 | 44 | private static class Forth { 45 | Fifth fifth; 46 | } 47 | 48 | private static class Fifth { 49 | @SerializedName("hello_here_i_am") 50 | boolean value; 51 | } 52 | ``` 53 | 54 | and end up with something like this (mileage may vary) to retrive this value: 55 | ```java 56 | public boolean extractValue(Response response) { 57 | if (response != null 58 | && response.first != null 59 | && response.first.second != null 60 | && response.first.second.third != null 61 | && response.first.second.third.forth != null 62 | && response.first.second.third.forth.fifth != null) { 63 | return response.first.second.third.forth.fifth.value; 64 | } 65 | return false; 66 | } 67 | ``` 68 | 69 | ### The *Flatten* way 70 | Class definition: 71 | ```java 72 | private static class Response { 73 | @Flatten("second::third::forth::fifth::hello_here_i_am") 74 | @SerializedName("first") 75 | Flattened value; 76 | } 77 | ``` 78 | 79 | Value retrieval: 80 | ```java 81 | private boolean extractValue(Response response) { 82 | if (response != null 83 | && response.value != null) { 84 | return response.value.get(); 85 | } 86 | return false; 87 | } 88 | ``` 89 | Off cause it doesn't eliminate *all* the null checks (and in this case (of boxed boolean) it would be wise to additionally call `response.value.hasValue()`), but it's a definite progress. 90 | 91 | ## Features 92 | * Eliminates the need in classes that are used only to get to the desired value. 93 | * Eliminates a lot of NULL checks 94 | * Eases the pain of migration to other response model 95 | * Supports custom deserialization (if a type wrapped in Flattened<> has registered TypeAdapter it will be deserialized with it) 96 | * Utilizes `Null Object Pattern` for the cases when parser meets a *dead-end* in a parsing way (for example, when `third` is null, then `value` won't be null, but `value.hasValue()` will return `false`) 97 | 98 | ## Setup 99 | Register type adapter for a `Flattened` type with `FlattenJsonDeserializer` type adapter (pass to it root classes that contain `Flatten` annotations, for example in case of former response it would be `new FlattenJsonDeserializer(Response.class)` ) 100 | ```java 101 | final Gson gson = new GsonBuilder() 102 | .registerTypeAdapter(Flattened.class, new FlattenJsonDeserializer( 103 | MyFirstFlatten.class, 104 | MySecondFlatten.class, 105 | MyThirdFlatten.class 106 | )) 107 | .create(); 108 | ``` 109 | 110 | Use this `gson` to deserialze your objects. 111 | 112 | ## License 113 | 114 | ``` 115 | Copyright 2015 Dimitry Ivanov (mail@dimitryivanov.ru) 116 | 117 | Licensed under the Apache License, Version 2.0 (the "License"); 118 | you may not use this file except in compliance with the License. 119 | You may obtain a copy of the License at 120 | 121 | http://www.apache.org/licenses/LICENSE-2.0 122 | 123 | Unless required by applicable law or agreed to in writing, software 124 | distributed under the License is distributed on an "AS IS" BASIS, 125 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 126 | See the License for the specific language governing permissions and 127 | limitations under the License. 128 | ``` 129 | 130 | -------------------------------------------------------------------------------- /library/src/main/java/ru/noties/flatten/FlattenJsonDeserializer.java: -------------------------------------------------------------------------------- 1 | package ru.noties.flatten; 2 | 3 | import com.google.gson.JsonDeserializationContext; 4 | import com.google.gson.JsonDeserializer; 5 | import com.google.gson.JsonElement; 6 | import com.google.gson.JsonObject; 7 | import com.google.gson.JsonParseException; 8 | 9 | import java.lang.reflect.Field; 10 | import java.lang.reflect.ParameterizedType; 11 | import java.lang.reflect.Type; 12 | import java.util.ArrayList; 13 | import java.util.Collections; 14 | import java.util.HashMap; 15 | import java.util.List; 16 | import java.util.Map; 17 | 18 | /** 19 | * Created by Dimitry Ivanov on 29.10.2015. 20 | */ 21 | public class FlattenJsonDeserializer implements JsonDeserializer> { 22 | 23 | private final Map> mCache; 24 | 25 | public FlattenJsonDeserializer(Class... roots) throws IllegalStateException { 26 | if (roots == null 27 | || roots.length == 0) { 28 | throw new IllegalStateException("One must specify at least one class, that contains @Flatten annotation"); 29 | } 30 | this.mCache = buildCache(roots); 31 | } 32 | 33 | private static Map> buildCache(Class... roots) { 34 | 35 | final Map> cache = new HashMap<>(); 36 | 37 | for (Class root: roots) { 38 | 39 | final Field[] fields = root.getDeclaredFields(); 40 | if (fields == null 41 | || fields.length == 0) { 42 | throw new IllegalStateException("Internal error, cannot access any of class fields, class: " + root); 43 | } 44 | 45 | Flatten flatten; 46 | 47 | Type type; 48 | String path; 49 | 50 | FlattenCacheItem cacheItem; 51 | List list; 52 | 53 | for (Field field : fields) { 54 | 55 | if (!field.isAnnotationPresent(Flatten.class)) { 56 | continue; 57 | } 58 | 59 | flatten = field.getAnnotation(Flatten.class); 60 | path = flatten.value(); 61 | type = getType(field.getGenericType()); 62 | 63 | if (type == null) { 64 | throw new IllegalStateException("Element `" + field.getName() + "` in class: `" + root + "` is not wrapped into `Flattened<>`"); 65 | } 66 | 67 | cacheItem = new FlattenCacheItem(path.split("::")); 68 | 69 | if (cache.containsKey(type)) { 70 | cache.get(type).add(cacheItem); 71 | } else { 72 | list = new ArrayList<>(); 73 | list.add(cacheItem); 74 | cache.put(type, list); 75 | } 76 | } 77 | 78 | } 79 | 80 | return Collections.unmodifiableMap(cache); 81 | } 82 | 83 | private static Type getType(Type type) { 84 | if (type instanceof ParameterizedType) { 85 | final ParameterizedType parameterizedType = (ParameterizedType) type; 86 | final Type[] params = parameterizedType.getActualTypeArguments(); 87 | if (params != null 88 | && params.length > 0) { 89 | return params[0]; 90 | } 91 | } 92 | return null; 93 | } 94 | 95 | @Override 96 | public Flattened deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { 97 | 98 | final Type type = getType(typeOfT); 99 | 100 | // retrieve cache items fot type 101 | final List items = mCache.get(type); 102 | if (items == null) { 103 | return null; 104 | } 105 | 106 | final JsonObject root = json != null && json.isJsonObject() ? json.getAsJsonObject() : null; 107 | if (root == null) { 108 | return FlattenedImpl.EMPTY; 109 | } 110 | 111 | JsonElement element; 112 | 113 | for (FlattenCacheItem item : items) { 114 | 115 | element = root; 116 | 117 | for (String pathElement : item.path) { 118 | 119 | if (element.isJsonObject()) { 120 | element = ((JsonObject) element).get(pathElement); 121 | } 122 | 123 | if (element == null) { 124 | break; 125 | } 126 | } 127 | 128 | if (element != null) { 129 | return new FlattenedImpl<>(context.deserialize(element, type)); 130 | } 131 | } 132 | 133 | return FlattenedImpl.EMPTY; 134 | } 135 | 136 | private static class FlattenCacheItem { 137 | 138 | final String[] path; 139 | 140 | private FlattenCacheItem(String[] path) { 141 | this.path = path; 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /library/src/test/java/ru/noties/flatten/FlattenTest.java: -------------------------------------------------------------------------------- 1 | package ru.noties.flatten; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | import com.google.gson.JsonDeserializationContext; 6 | import com.google.gson.JsonDeserializer; 7 | import com.google.gson.JsonElement; 8 | import com.google.gson.JsonParseException; 9 | import com.google.gson.annotations.SerializedName; 10 | 11 | import junit.framework.TestCase; 12 | 13 | import java.lang.reflect.Type; 14 | import java.util.List; 15 | 16 | /** 17 | * Created by Dimitry Ivanov on 29.10.2015. 18 | */ 19 | public class FlattenTest extends TestCase { 20 | 21 | private Gson mGson; 22 | 23 | public void testNoClassesPassed() { 24 | try { 25 | buildGson(); 26 | assertTrue(false); 27 | } catch (IllegalStateException e) { 28 | assertTrue(true); 29 | } 30 | } 31 | 32 | public void testClassNoFields() { 33 | try { 34 | buildGson(EmptyClass.class); 35 | assertTrue(false); 36 | } catch (IllegalStateException e) { 37 | assertTrue(true); 38 | } 39 | } 40 | 41 | public void testElementsNotWrapped() { 42 | try { 43 | buildGson(NotWrappedClass.class); 44 | assertTrue(false); 45 | } catch (IllegalStateException e) { 46 | assertTrue(true); 47 | } 48 | } 49 | 50 | public void testFlattenedPrimitive() { 51 | buildGson(FlattenedSinglePrimitive.class); 52 | 53 | final String json = "{ \"i\": { \"first_object\": { \"second_object\": 33 } } }"; 54 | 55 | final Flattened i = mGson.fromJson(json, FlattenedSinglePrimitive.class).i; 56 | 57 | assertTrue(i != null && i.get() == 33); 58 | } 59 | 60 | public void testFlattenPrimitiveNullAlongAWay() { 61 | 62 | buildGson(FlattenedSinglePrimitive.class); 63 | 64 | final String json = "{ \"i\": { \"first_object\": null } }"; 65 | 66 | final Flattened i = mGson.fromJson(json, FlattenedSinglePrimitive.class).i; 67 | 68 | assertFalse(i == null); 69 | assertTrue(!i.hasValue()); 70 | } 71 | 72 | public void testWithCustomDeserializer() { 73 | 74 | final Gson gson = new GsonBuilder() 75 | .registerTypeAdapter(Flattened.class, new FlattenJsonDeserializer(FlattenedSinglePrimitive.class)) 76 | .registerTypeAdapter(Integer.class, new JsonDeserializer() { 77 | @Override 78 | public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { 79 | final boolean out = json.getAsBoolean(); 80 | return out ? 1 : 0; 81 | } 82 | }) 83 | .create(); 84 | 85 | final String json = "{ \"i\": { \"first_object\": { \"second_object\": true } } }"; 86 | final Flattened i = gson.fromJson(json, FlattenedSinglePrimitive.class).i; 87 | 88 | assertFalse(i == null); 89 | assertTrue(i.hasValue()); 90 | assertTrue(i.get() == 1); 91 | } 92 | 93 | public void testElementsOfOneTypeDifferentPaths() { 94 | buildGson(FlattenedMultiple.class); 95 | 96 | final String json = "{" + 97 | " \"first\": { \"second\": { \"third\": { \"forth\": { \"fifth\": { \"some_long\": 99, \"some_string\": \"first string ever\" } } } } }," + 98 | " \"second\": { \"fifth\": { \"forth\": { \"third\": { \"second\": { \"some_long\": 22, \"some_string\": \"second string ever\" } } } } }" + 99 | "}"; 100 | 101 | final FlattenedMultiple multiple = mGson.fromJson(json, FlattenedMultiple.class); 102 | 103 | final Flattened first = multiple.first; 104 | final Flattened second = multiple.second; 105 | 106 | assertTrue(first != null && second != null); 107 | assertTrue(first.hasValue() && second.hasValue()); 108 | 109 | SimpleType simpleType = first.get(); 110 | assertTrue(simpleType.some_long == 99); 111 | assertTrue(simpleType.some_string.equals("first string ever")); 112 | 113 | simpleType = second.get(); 114 | assertTrue(simpleType.some_long == 22); 115 | assertTrue(simpleType.some_string.equals("second string ever")); 116 | } 117 | 118 | public void testSerializedName() { 119 | 120 | buildGson(FlattenedSerilizedName.class); 121 | 122 | final String json = "{ \"serialized_name\": { \"second\": true } }"; 123 | 124 | final Flattened b = mGson.fromJson(json, FlattenedSerilizedName.class).bool; 125 | 126 | assertTrue(b != null && b.hasValue()); 127 | assertTrue(b.get()); 128 | } 129 | 130 | public void testBoxedBoolean() { 131 | 132 | buildGson(FlattenedBoolean.class); 133 | 134 | final String json = "{\"first\":{\"second\":{\"third\":{\"forth\":{fifth:{\"hello_here_i_am\":true}}}}}}"; 135 | 136 | final FlattenedBoolean b = mGson.fromJson(json, FlattenedBoolean.class); 137 | 138 | assertTrue(b.value.get()); 139 | } 140 | 141 | public void testList() { 142 | 143 | buildGson(FlattenedList.class); 144 | 145 | final String json = "{\"some\":{\"where\":{\"beyond\":{\"the\":{\"sea\":[0,1,2,3,4,5,6,7,8,9]}}}}}"; 146 | 147 | final FlattenedList flattenedList = mGson.fromJson(json, FlattenedList.class); 148 | assertTrue(String.format("list: %s", flattenedList.list.get()), flattenedList.list != null && flattenedList.list.hasValue()); 149 | assertTrue(String.format("list: %s", flattenedList.list.get()), flattenedList.list.get().size() == 10); 150 | } 151 | 152 | private void buildGson(Class... classes) { 153 | mGson = new GsonBuilder() 154 | .registerTypeAdapter(Flattened.class, new FlattenJsonDeserializer(classes)) 155 | .serializeNulls() 156 | .create(); 157 | } 158 | 159 | 160 | private static class EmptyClass {} 161 | 162 | private static class NotWrappedClass { 163 | @Flatten("") 164 | Void v; 165 | } 166 | 167 | private static class FlattenedSinglePrimitive { 168 | 169 | @Flatten("first_object::second_object") 170 | Flattened i; 171 | } 172 | 173 | private static class SimpleType { 174 | private long some_long; 175 | private String some_string; 176 | } 177 | 178 | private static class FlattenedMultiple { 179 | 180 | @Flatten("second::third::forth::fifth") 181 | Flattened first; 182 | 183 | @Flatten("fifth::forth::third::second") 184 | Flattened second; 185 | } 186 | 187 | private static class FlattenedSerilizedName { 188 | 189 | @Flatten("second") 190 | @SerializedName("serialized_name") 191 | Flattened bool; 192 | } 193 | 194 | private static class FlattenedBoolean { 195 | 196 | @Flatten("second::third::forth::fifth::hello_here_i_am") 197 | @SerializedName("first") 198 | Flattened value; 199 | } 200 | 201 | private static class FlattenedList { 202 | 203 | @Flatten("where::beyond::the::sea") 204 | @SerializedName("some") 205 | Flattened> list; 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | --------------------------------------------------------------------------------