-
Notifications
You must be signed in to change notification settings - Fork 1
BI-2005 - Expand Exp Template #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a542e76
Added migration for new experiment sub unit fields
nickpalladino 5680414
Added validations for geocoordinates
nickpalladino 07739d2
Removed unused imports
nickpalladino 1912e71
Merge branch 'develop' into feature/BI-2005
nickpalladino 2ad3f90
Moved geocoordinate validation to be called from observation unit val…
nickpalladino 319d9cf
Added new columns to test file creation
nickpalladino 9a362fa
Added columns for experiment controller tests
nickpalladino 8137891
More test fixes
nickpalladino ce54b7e
Fix elevation not being added to geocoordinates
nickpalladino 8003d13
Added rtk to additionalinfo
nickpalladino 87b1d72
Fix geojson serialization problem
nickpalladino 6c36cce
Merge branch 'develop' into feature/BI-2005
nickpalladino 889408f
Merge branch 'develop' into feature/BI-2005
nickpalladino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/main/java/org/breedinginsight/api/serializer/CustomObjectMapperFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * See the NOTICE file distributed with this work for additional information | ||
| * regarding copyright ownership. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.breedinginsight.api.serializer; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonFactory; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.module.SimpleModule; | ||
| import com.google.gson.Gson; | ||
| import io.micronaut.context.annotation.Factory; | ||
| import io.micronaut.context.annotation.Replaces; | ||
| import io.micronaut.core.annotation.Nullable; | ||
| import io.micronaut.jackson.JacksonConfiguration; | ||
| import io.micronaut.jackson.ObjectMapperFactory; | ||
| import org.brapi.client.v2.JSON; | ||
| import org.brapi.v2.model.BrApiGeoJSON; | ||
|
|
||
| import javax.inject.Singleton; | ||
|
|
||
| /** | ||
| * Add custom serializers to Micronaut's Jackson ObjectMapper | ||
| */ | ||
| @Factory | ||
| public class CustomObjectMapperFactory extends ObjectMapperFactory { | ||
|
|
||
| @Singleton @Replaces(ObjectMapper.class) | ||
| @Override | ||
| public ObjectMapper objectMapper(@Nullable JacksonConfiguration jacksonConfiguration, @Nullable JsonFactory jsonFactory) { | ||
| ObjectMapper mapper = super.objectMapper(jacksonConfiguration, jsonFactory); | ||
|
|
||
| // Jackson was not properly serializing geojson objects from com.github.filosganga.geogson | ||
| // which is made to work with gson and part of the brapi client object models so just use gson to | ||
| // do the serialization instead of jackson for this case | ||
| SimpleModule module = new SimpleModule(); | ||
| Gson gson = new JSON().getGson(); | ||
| module.addSerializer(new GsonBasedSerializer<>(BrApiGeoJSON.class, gson)); | ||
| mapper.registerModule(module); | ||
|
|
||
| return mapper; | ||
| } | ||
| } | ||
44 changes: 44 additions & 0 deletions
44
src/main/java/org/breedinginsight/api/serializer/GsonBasedSerializer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * See the NOTICE file distributed with this work for additional information | ||
| * regarding copyright ownership. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.breedinginsight.api.serializer; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonGenerator; | ||
| import com.fasterxml.jackson.databind.SerializerProvider; | ||
| import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
| import com.google.gson.Gson; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Jackson Serializer that uses Gson to do the serialization | ||
| */ | ||
| public class GsonBasedSerializer<T> extends StdSerializer<T> { | ||
|
|
||
| private final Gson gson; | ||
|
|
||
| public GsonBasedSerializer(Class<T> t, Gson gson) { | ||
| super(t); | ||
| this.gson = gson; | ||
| } | ||
|
|
||
| @Override | ||
| public void serialize(T value, JsonGenerator gen, SerializerProvider provider) throws IOException { | ||
| String json = gson.toJson(value); | ||
| gen.writeRawValue(json); // Using writeRawValue to avoid double quoting | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this override be used every time an
ObjectMapperis injected?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya