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

[Question] Probably I somehow incorrectly configure the application, but when I get it I get an error #115

Closed
BorzdeG opened this issue Apr 28, 2018 · 3 comments
Labels

Comments

@BorzdeG
Copy link

BorzdeG commented Apr 28, 2018

source: https://github.com/BorzdeG/samples-kotlin-subprojects/tree/kotlinx.serialization

Exception in thread "main" java.lang.IllegalArgumentException: JSON at 5: Expected '{, kind: CLASS'
	at kotlinx.serialization.json.JSON$Companion.fail(JSON.kt:190)
	at kotlinx.serialization.json.JSON$Companion.require(JSON.kt:186)
	at kotlinx.serialization.json.JSON$Companion.access$require(JSON.kt:54)
	at kotlinx.serialization.json.JSON$JsonInput.readBegin(JSON.kt:349)
	at demo.common.ChildModelSerializer.load(ChildModel.kt:25)
	at demo.common.ChildModelSerializer.load(ChildModel.kt:9)
	at kotlinx.serialization.KInput.readSerializableValue(Serialization.kt:243)
	at kotlinx.serialization.ElementValueInput.readSerializableElementValue(Serialization.kt:438)
	at demo.common.ParentModelSerializer.load(ParentModel.kt:35)
	at demo.common.ParentModelSerializer.load(ParentModel.kt:15)
	at kotlinx.serialization.KInput.read(Serialization.kt:209)
	at kotlinx.serialization.json.JSON.parse(JSON.kt:47)
	at kotlinx.serialization.json.JSON$Companion.parse(JSON.kt:57)
	at demo.client.jvm.ClientJvmKt.main(ClientJvm.kt:28)
@sandwwraith
Copy link
Member

sandwwraith commented Apr 29, 2018

The correct approach to write deserializing code manually is to use input returned from readBegin. Also you always need to call readElement to determine current element to read (in json, they can go in other order comparing to what you have in class) So code for your ChildModel will look like this:

override fun load(input: KInput): ChildModel {
		val newInput = input.readBegin(serialClassDesc)
                val i = newInput.readElement(serialClassDesc)
                check(i == 0) // if you have more than one field, make "when" here
		val cf = newInput.readStringElementValue(serialClassDesc, 0)
		newInput.readEnd(serialClassDesc)
		return ChildModel(cf = cf)
	}

@sandwwraith
Copy link
Member

But I'm wondering why you're trying to write the same code that plugin will generate for you...

@JoaquimLey
Copy link

JoaquimLey commented Oct 16, 2018

It might not be the case for @BorzdeG, but I got a similar error.
I'm writing about my exp. since it might help others coming here with a similar situation.


In my case, I was trying to parse my object from an empty String, so make sure your String is not null and that in fact, matches your Model.class

e.g:

If

class FooUserModel(name: String)

Is updated to

class FooUserModel(firstName: String, lastName: String)

And the model you have stored/trying to parse doesn't match 1-to-1, this is the logical error to be thrown, so watch out for that.

JoaquimLey added a commit to JoaquimLey/transport-eta that referenced this issue Oct 16, 2018
Also, fixes and issue where the String was default to  which made the serialization fail:
 - Kotlin/kotlinx.serialization#115

#17, #69
JoaquimLey added a commit to JoaquimLey/transport-eta that referenced this issue Oct 17, 2018
)

* Scaffold sharedpreferences module

- Attach to store implemetnation
- Mock data currently being returned

Some housekeeping.

* Small configurations for CI

Still not working, wanted to make mock work with debug but variants still compain.

* Test removing ViewModelModule

* Ci why you no work?

* Fix lints on CI

* Working stuff for CI

* housekeeping mobile-ui/build.gradle

Had to make some changtes while debuging CI fails. This change still makes sense IMO.

#69

* Rename data package to include project name
#69

* Remove unecessary .gitignore from other packages

Maintenece commit, not really related to this branch feature.

* Manifest cleanup and format

* Scaffold stuff for stream episode 17

Some basic ideas just so I know what I'm supposed to continue, a lot of TODOs
so lint warns me.

For #17
Ref #69

* Housekeeping from previous commit

* Fix typo in readme

Changed the copy on the stream log section

* Include kotlinx.serialization experimental library for sharedPrefs

This will be included in the stblib from Kotlin 1.3.

#17, #69

* Make SharedPrefTransport model @kotlinx.serialization.Serializable

Also, fixes and issue where the String was default to  which made the serialization fail:
 - Kotlin/kotlinx.serialization#115

#17, #69

* SharedPrefMapper tests

- Created necessary factory/mock data classes for the SharedPref module

Named the mock classes with the SharedPref prefix for #66

#17 #69

* Initial tests for FrameworkLocalStorageImpl

Lacking SharedPreferences test setup
  - Will probably need to move all the Android test libs to androidx variant.

#17 #69

* Include stream episode PR to README
JoaquimLey added a commit to JoaquimLey/transport-eta that referenced this issue Oct 22, 2018
* Scaffold sharedpreferences module

- Attach to store implemetnation
- Mock data currently being returned

Some housekeeping.

* Small configurations for CI

Still not working, wanted to make mock work with debug but variants still compain.

* Test removing ViewModelModule

* Ci why you no work?

* Fix lints on CI

* Working stuff for CI

* housekeeping mobile-ui/build.gradle

Had to make some changtes while debuging CI fails. This change still makes sense IMO.

#69

* Rename data package to include project name
#69

* Remove unecessary .gitignore from other packages

Maintenece commit, not really related to this branch feature.

* Manifest cleanup and format

* Scaffold stuff for stream episode 17

Some basic ideas just so I know what I'm supposed to continue, a lot of TODOs
so lint warns me.

For #17
Ref #69

* Housekeeping from previous commit

* Fix typo in readme

Changed the copy on the stream log section

* Include kotlinx.serialization experimental library for sharedPrefs

This will be included in the stblib from Kotlin 1.3.

#17, #69

* Make SharedPrefTransport model @kotlinx.serialization.Serializable

Also, fixes and issue where the String was default to  which made the serialization fail:
 - Kotlin/kotlinx.serialization#115

#17, #69

* Implement initial SharedPref slot save logic

#17, #69

* Add stream ep to README, ignore failing test on shared pref

#17, #69
JoaquimLey added a commit to JoaquimLey/transport-eta that referenced this issue Oct 30, 2018
* Scaffold sharedpreferences module

- Attach to store implemetnation
- Mock data currently being returned

Some housekeeping.

* Small configurations for CI

Still not working, wanted to make mock work with debug but variants still compain.

* Test removing ViewModelModule

* Ci why you no work?

* Fix lints on CI

* Working stuff for CI

* housekeeping mobile-ui/build.gradle

Had to make some changtes while debuging CI fails. This change still makes sense IMO.

#69

* Rename data package to include project name
#69

* Remove unecessary .gitignore from other packages

Maintenece commit, not really related to this branch feature.

* Manifest cleanup and format

* Scaffold stuff for stream episode 17

Some basic ideas just so I know what I'm supposed to continue, a lot of TODOs
so lint warns me.

For #17
Ref #69

* Housekeeping from previous commit

* Fix typo in readme

Changed the copy on the stream log section

* Include kotlinx.serialization experimental library for sharedPrefs

This will be included in the stblib from Kotlin 1.3.

#17, #69

* Make SharedPrefTransport model @kotlinx.serialization.Serializable

Also, fixes and issue where the String was default to  which made the serialization fail:
 - Kotlin/kotlinx.serialization#115

#17, #69

* Test for SharedPreferences all slots free, saves to Slot.ONE

#17, #69

* Final touches on frameworkLocalStorageTest

Still missing clear all, getAll and make sure observeSharedPreferencesChanges
emitts for any changes (missing tests basically).

#17, #69

* Add episode to README

#84

* Stream Episode 19 (#84)

* Final touches on frameworkLocalStorageTest

Still missing clear all, getAll and make sure observeSharedPreferencesChanges
emitts for any changes (missing tests basically).

#17, #69

* Add episode to README

#84

* Add klint link

* Create stub test class on :presentation

This is a reminder for eventual instrumentation tests, stll not sure if makes
sense to use though.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants