Skip to content
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

support for multiple languages in geocoding model objects #1025

Closed
wants to merge 1 commit into from

Conversation

osana
Copy link
Contributor

@osana osana commented May 8, 2019

This PR will resolve #446

There were two parts to this PR:

  • Geocoding module will not depend on AutoValue. This makes it easier to do json parsing customization.
  • Add custom parsing of fileds like:
    text_{language} fields into a Map (lang -> text string in that language)

Added tests.

@osana osana force-pushed the osana-geocode-languages branch 6 times, most recently from 4e0f480 to ee12d09 Compare May 10, 2019 02:31
@osana osana requested a review from LukasPaczos May 10, 2019 14:02
@osana osana added this to the v4.9.0 milestone May 10, 2019
@osana osana changed the title support for multiple languages in geocoding requests support for multiple languages in geocoding model objects May 10, 2019
TypeAdapter<String> stringAdapter = this.stringAdapter;
if (stringAdapter == null) {
this.stringAdapter = stringAdapter;
stringAdapter = gson.getAdapter(String.class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the adapter always uses String.class, does it have to be lazily initialized in each method instead once in the class field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the part that I was not sure about.
The code is extracted from generated AutoValue.
There is an instance variable: stringAdapter which will be Lazily initialized.
I am not sure why there is a need to keep a local copy of this. stringAdapter

Decided to keep it as is. I think I should address that part separately.

}

@Nullable
List<String> readLanguages(@Nullable List<String> languages,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The passed collections references seem to always be nulls and are initialized only here, do we need to pass them in the first place then?

Copy link
Contributor Author

@osana osana May 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe readLanguages will be called multiple times. In case of CarmenContext json could look like:

"context": [
{
"id": "country.9053006287256050",
"short_code": "us",
"wikidata": "Q30",
"text_ru": "Соединённые Штаты Америки",
"language_ru": "ru",
"text": "Соединённые Штаты Америки",
"language": "ru",
"text_fr": "États-Unis",
"language_fr": "fr"
}
]
}

so it will be called to read:
"language_ru": "ru",
then to read:
"language_fr": "fr"

Copy link
Contributor

@LukasPaczos LukasPaczos May 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be called multiple times with the same list as an argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. JsonReader is parsing each key/value as they come in. We cannot get all the language_* pairs (and similarly for other pairs and JsonWriter). I believe TypeAdapters are more efficient then JsonSerializer/Deserializer as do not have an intermediate parsed state. Because of that though it is a bit more restrictive.

@@ -48,7 +49,7 @@
* @since 1.0.0
*/
@Keep
public final class Feature implements GeoJson {
public final class Feature implements GeoJson, Serializable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the advantage of making Feature/FeatureCollection serializable now? If we'd like to make them serializable in general, why not make GeoJson implement Serializable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed inconsistency that felt odd, so decided to add it there. I think you are right: we can just add Serializable to GeoJson. Will experiment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decide to remove these changes from this PR.
I think your suggestion is a valid one and should be addressed in a separate PR.

@LukasPaczos LukasPaczos self-requested a review May 13, 2019 14:39
@LukasPaczos
Copy link
Contributor

Whoops, didn't mean to approve, only comment.

@langsmith
Copy link

cc @kbauhaus as fyi that this is moving

@osana osana force-pushed the osana-geocode-languages branch 4 times, most recently from 6d0aea5 to fdda347 Compare May 14, 2019 21:36
@osana osana force-pushed the osana-geocode-languages branch from fdda347 to a35aa3b Compare May 17, 2019 04:00
@osana osana self-assigned this May 17, 2019
@LukasPaczos
Copy link
Contributor

I think this PR is functionally fine, but the style is off because it comes from generated code. We're going to need to maintain it manually now, so it should be cleaned up before it's merged to master in my opinion.

@osana
Copy link
Contributor Author

osana commented May 17, 2019

Thank you for 👀 @LukasPaczos
Would love to hear your suggestions.

@LukasPaczos
Copy link
Contributor

I'm thinking about the left comments like unnecessary local object copies, lazy inits, or null checks.

@osana
Copy link
Contributor Author

osana commented May 17, 2019

Lazy init for TypeAdapter does not make sense - agree with you.
I do not understand why the generated code had a double assignment.
I can get rid of those and then see what happens.

I do think that some TypeAdapters should be lazily initialized as those fields are rarely used like foBoundingBox, etc.

@stale stale bot added the Archived Issue archived due to lack of activity label Jul 16, 2019
@stale
Copy link

stale bot commented Jul 16, 2019

This pull request has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this Jul 16, 2019
@langsmith langsmith reopened this Jul 16, 2019
@stale stale bot removed the Archived Issue archived due to lack of activity label Jul 16, 2019
@stale stale bot added the Archived Issue archived due to lack of activity label Sep 14, 2019
@stale
Copy link

stale bot commented Sep 14, 2019

This pull request has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this Sep 14, 2019
@langsmith langsmith reopened this Sep 14, 2019
@stale stale bot removed the Archived Issue archived due to lack of activity label Sep 14, 2019
@langsmith langsmith modified the milestones: v4.9.0, 4.10.0 Sep 25, 2019
@stale stale bot added the Archived Issue archived due to lack of activity label Nov 24, 2019
@stale
Copy link

stale bot commented Nov 24, 2019

This pull request has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this Nov 24, 2019
@langsmith langsmith reopened this Nov 25, 2019
@stale stale bot removed the Archived Issue archived due to lack of activity label Nov 25, 2019
@stale stale bot added the Archived Issue archived due to lack of activity label Jan 24, 2020
@stale
Copy link

stale bot commented Jan 24, 2020

This pull request has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Archived Issue archived due to lack of activity Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add geocoding API for setting multiple languages
3 participants