I have a MerchantAgent document who inherits a Partner document. To update the MerchantAgent document, i created an update function like below
#Document(collection = "partner")
open class Partner {
#Id
open lateinit var partnerId: String
lateinit var code: String
open lateinit var name: String
open lateinit var address: String
}
#Document(collection = "partner")
#TypeAlias("merchant_agent")
data class MerchantAgent(
override var name: String,
override var address: String,
var globalId: String,
var idTerminal: String
) : Partner() {
fun update(form: MerchantAgent): MerchantAgent {
return this.copy(
name = form.name,
address = form.address,
globalId = form.globalId,
idTerminal = form.idTerminal
}
}
when i start my application i have the below error
Caused by: org.springframework.data.mapping.MappingException:
Ambiguous field mapping detected! Both public java.lang.String
Partner.name and private java.lang.String MerchantAgent.name
map to the same field name name! Disambiguate using #Field annotation!
Related
There's a request that i'm using and it's parameter name is __parameter10/02/2020, the date is sent into request.
Is there a way to deserialize this using the Property annotation? Also how can i do this with the custom serializer?
Json Sample:
{"yearly_return10/02/2020" : "2.87", "__monthlyreturn_current10/02/2020": "-0.0853703899653",}
You may try #JsonAnySetter
class Response {
lateinit var yearlyReturn: BigDecimal
lateinit var monthlyReturnCurrent: BigDecimal
#JsonAnySetter
fun set(key: String, value: String) {
when {
key.contains("yearly_return") -> yearlyReturn = BigDecimal(value)
key.contains("monthlyreturn_current") -> monthlyReturnCurrent = BigDecimal(value)
}
}
}
val objectMapper: ObjectMapper = ObjectMapper().registerModules(
ParameterNamesModule(),
Jdk8Module(),
JavaTimeModule(),
KotlinModule()
)
val response = objectMapper.readValue<Response>("""{"yearly_return10/02/2020" : "2.87", "__monthlyreturn_current10/02/2020": "-0.0853703899653"}""")
I'm trying to develop a CorDapp using the example here. I've added two modules into my project, one for contracts and the other one for flows. I've added test cases for my contract and it works fine, but test cases for flow fail on setup stage. Here's the code of my test class
#TestInstance(TestInstance.Lifecycle.PER_CLASS)
class SharedInformationFlowTests {
private lateinit var network: MockNetwork
private lateinit var a: StartedMockNode
private val proposal = LedgerUpdateProposal.testProposal()
#BeforeAll
fun setup() {
val params = MockNetworkParameters(cordappsForAllNodes = listOf(
TestCordapp.findCordapp("com.something.contract")
))
network = MockNetwork(params) //fails here
a = network.createPartyNode()
network.runNetwork()
}
#AfterAll
fun tearDown() {
network.stopNodes()
}
And here are the error messages I get:
[WARN] 13:42:52,620 [main] spi.SqlExceptionHelper. - SQL Error: 0, SQLState: null {changeSet=migration/vault-schema.changelog-v9.xml::update-vault-states::R3.Corda, databaseChangeLog=master.changelog.json}
[ERROR] 13:42:52,620 [main] spi.SqlExceptionHelper. - Connection is closed {changeSet=migration/vault-schema.changelog-v9.xml::update-vault-states::R3.Corda, databaseChangeLog=master.changelog.json}
net.corda.nodeapi.internal.persistence.CouldNotCreateDataSourceException: Could not create the
DataSource: Migration failed for change set migration/vault-schema.changelog-v9.xml::update-vault-states::R3.Corda:
Reason: net.corda.nodeapi.internal.persistence.HibernateConfigException: Could not create Hibernate configuration: Unable to open JDBC Connection for DDL execution
I think there's something wrong with the liquibase. I've tried adding changelog file to my resources/migration directory as advised here, but it doesn't seem to have any effect. Please help.
UPDATE Added schema
/**
* The family of com.sentinel.schemas for SharingInformationState.
*/
object SharingInformationSchema
/**
* An SharingInformationState schema.
*/
object SharingInformationSchemaV1 : MappedSchema(
schemaFamily = SharingInformationSchema.javaClass,
version = 1,
mappedTypes = listOf(PersistentSharingInformation::class.java)) {
override val migrationResource: String? = "sharing-information-schema-v1.changelog-master.xml"
#Entity
#Table(name = "persistent_sharing_information")
class PersistentSharingInformation(
#Column(name = "owner_id")
var dataOwnerId: Long,
#Column(name = "buyer_id")
var dataBuyerId: Long,
#Column(name = "start_date")
val startDate: String,
#Column(name = "end_date")
val endDate: String,
#Column(name = "shared_fields")
val sharedFieldsIds: String,
#Column(name = "agreement_status")
val agreementStatus: String,
#Column(name = "contract_type")
val contractType: String,
#Column(name = "linear_id")
var linearId: UUID
) : PersistentState() {
// Default constructor required by hibernate.
constructor() : this(0L, 0L,
"", "", "[]", "", "", UUID.randomUUID())
}
}
#BelongsToContract(com.package.contract.SharingInformationContract::class)
class SharingInformationState(val ourParty: Party,
val proposal: LedgerUpdateProposal,
override val linearId: UniqueIdentifier = UniqueIdentifier()) : LinearState, QueryableState {
override val participants: List<AbstractParty> = listOf(ourParty)
override fun generateMappedObject(schema: MappedSchema): PersistentState {
return when (schema) {
SharingInformationSchemaV1 -> SharingInformationSchemaV1.PersistentSharingInformation(
proposal.ownerId,
proposal.buyerId,
proposal.startDate,
proposal.endDate,
proposal.sharedFieldsIds.toString(),
proposal.agreementStatus.name,
proposal.contractType.name,
linearId.id
)
else -> throw IllegalArgumentException("Unrecognised schema $schema")
}
}
override fun supportedSchemas(): Iterable<MappedSchema> = listOf(SharingInformationSchemaV1)
}
#CordaSerializable
enum class AgreementStatus { APPROVED, REJECTED }
#CordaSerializable
enum class ContractType { CORPORATE, CONSUMER, MARKETING, BINDING }
I am trying to assign data to my class using the variable that I created. I want to use the variable as an instance of the membership class. Every time I pass any values I get an error.
error: no value passed for parameter '_number'
var member1 = membership()
error: unresolved reference: _number
member1._number = 1
I am getting this for all properties I try to pass anything to.
I tried to create the class without any constructors but I would still get errors. My goal is to create a list of the variables.
class membership(_number:Int, _name:String, _address:String, _zip:String, _phone:String, _memberSince:String, _memberType:Char)
{
var number: Int = _number;
var name: String = _name;
var address: String = _address;
var zip: String = _zip;
var phone: String = _phone;
var memberSince: String = _memberSince;
var memberType: Char = _memberType;
}
fun main(args: Array<String>) {
var member1 = membership()
member1._number = 1
member1._name = "George Jetson";
member1._address ="123 Main St.";
member1._zip = "99207";
member1._memberSince = "12/01/1997";
member1._memberType = 'L';
}
You have declared the class membership with the primary constructor that expects 7 parameters. Hence, you need to provide values for these parameters when you're instantiating this class:
var member1 = membership(
_number = 1,
_name = "George Jetson",
_address ="123 Main St.",
_zip = "99207",
_memberSince = "12/01/1997",
_memberType = 'L'
)
If you want to create an instance of the class first and then initialize its properties one-by-one, you need it to have a parameterless constructor:
class membership() {
However then you'll have to make all its properties nullable or lateinit because now you cannot provide their initial values upon construction:
class membership() {
var number: Int? = null
var name: String? = null
var address: String? = null
// etc
}
This way you'll be able to initialize them as you want in your question.
I am using Retrofit with simpleXMLConverter to get data out of an xml and use it in my android application. However, I am unable to bind the value of a certain tag on my value in my class. In my situation, I'm trying to bind the mtc:gas_type to my price variable in the Gasoline Class. I did manage to bind a value from a simple XML I found online with just 2 tags so it means I'm doing something wrong with this particular XML...
Error(Which means it can't find the tag):
java.lang.RuntimeException: org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy #org.simpleframework.xml.Element(data=false, name=mtc:gas_type, required=true, type=void) on field 'price' private double com.example.alexander.ridy.Model.domain.Gasoline.price for class com.example.alexander.ridy.Model.domain.Gasoline at line -1
at retrofit2.converter.simplexml.SimpleXmlResponseBodyConverter.convert(SimpleXmlResponseBodyConverter.java:44)
at retrofit2.converter.simplexml.SimpleXmlResponseBodyConverter.convert(SimpleXmlResponseBodyConverter.java:23)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:223)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:186)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:92)
at com.example.alexander.ridy.View.fragments.Ride.VehicleDetails$determineGasolineType$1.run(VehicleDetails.kt:101)
at java.lang.Thread.run(Thread.java:764)
Caused by: org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy #org.simpleframework.xml.Element(data=false, name=mtc:gas_type, required=true, type=void) on field 'price' private double com.example.alexander.ridy.Model.domain.Gasoline.price for class com.example.alexander.ridy.Model.domain.Gasoline at line -1
at org.simpleframework.xml.core.Composite.validate(Composite.java:644)
at org.simpleframework.xml.core.Composite.readElements(Composite.java:449)
at org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
at org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
at org.simpleframework.xml.core.Composite.read(Composite.java:201)
at org.simpleframework.xml.core.Composite.read(Composite.java:148)
at org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
at org.simpleframework.xml.core.Persister.read(Persister.java:625)
at org.simpleframework.xml.core.Persister.read(Persister.java:606)
at org.simpleframework.xml.core.Persister.read(Persister.java:584)
at org.simpleframework.xml.core.Persister.read(Persister.java:562)
at retrofit2.converter.simplexml.SimpleXmlResponseBodyConverter.convert(SimpleXmlResponseBodyConverter.java:36)
at retrofit2.converter.simplexml.SimpleXmlResponseBodyConverter.convert(SimpleXmlResponseBodyConverter.java:23)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:223)
at retrofit2.OkHttpCall.execute(OkHttpCall.java:186)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:92)
at com.example.alexander.ridy.View.fragments.Ride.VehicleDetails$determineGasolineType$1.run(VehicleDetails.kt:101)
at java.lang.Thread.run(Thread.java:764)
XML:
https://www.globalpetrolprices.com/api/getGasXML_weekly.php?gasoline_diesel=2&rate=EUR&countries=183&p=c5ab37e86d514beadb60d3d3d682f363
Endpoint interface:
interface Endpoint {
#GET("/api/getGasXML_weekly.php?gasoline_diesel=2&rate=LC&countries=183&p=c5ab37e86d514beadb60d3d3d682f363")
fun getDiesel(): Call<Gasoline>
#GET("/api/getGasXML_weekly.php?gasoline_diesel=1&rate=LC&countries=183&p=c5ab37e86d514beadb60d3d3d682f363")
fun getSuper95(): Call<Gasoline>
#GET("/api/getGasXML_weekly.php?gasoline_diesel=3&rate=LC&countries=183&p=c5ab37e86d514beadb60d3d3d682f363")
fun getLPG(): Call<Gasoline>
RetrofitClientInstance:
class RetrofitClientInstance {
private var retrofit: Retrofit? = null
private val BASE_URL = "https://www.globalpetrolprices.com"
fun getRetrofitInstance(): Retrofit? {
retrofit = retrofit2.Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(create())
.build()
return retrofit
}
Gasoline Class:
#Root(strict = false) class Gasoline {
#field:Element(name="mtc:gas_type")
var price : Double = 0.0
lateinit var gasolineType : GasolineType
constructor()
The call:
fun determineGasolineType() {
val mySpinner = view?.findViewById(R.id.gasolineSpinner) as Spinner
val text = mySpinner.selectedItem.toString()
val service = RetrofitClientInstance().getRetrofitInstance()!!.create(Endpoint::class.java!!)
lateinit var call : Call<Gasoline>
lateinit var resp : Response<Gasoline>
Thread({
resp = service.getDiesel().execute()
Log.d("",resp.body().toString())
}).start()
My app needs to parcel some objects with realm list attributes. This is the error:
/StudioProjects/ML/dat-core-android/datcorelibrary/build/tmp/kapt3/stubs/release/com/ret/datcorelibrary/model/UserTest.java:29: error: Parceler: Unable to find read/write generator for type io.realm.RealmList for com.retoglobal.datingcorelibrary.model.UserTest#photos
Find below the main classes:
UserTest class
#Parcel(implementations = arrayOf(UserTestRealmProxy::class),
value = Parcel.Serialization.BEAN)
#RealmClass
open class UserTest(
#PrimaryKey open var id: String = "",
open var years : Int = 0,
#SerializedName("profile_photo") open var profilePhoto: ProfilePhoto? = ProfilePhoto("www", "fd"),
open var location : Property? = null,
open var town : String? = "",
open var username : String? = "") : RealmObject()
{
#ParcelPropertyConverter(RealmUserTestParcelConverter::class)
open var photos : RealmList<ProfilePhoto>? = null
set
}
class RealmUserTestParcelConverter : RealmListParcelConverter<ProfilePhoto>() {
override fun itemFromParcel(parcel: android.os.Parcel?): ProfilePhoto {
return Parcels.unwrap(parcel?.readParcelable<Parcelable>(ProfilePhoto::class.java.classLoader))
}
override fun itemToParcel(item: ProfilePhoto?, parcel: android.os.Parcel?) {
parcel?.writeParcelable(Parcels.wrap(ProfilePhoto::class.java, item), 0)
}
}
ProfilePhoto class
#Parcel(implementations = arrayOf(ProfilePhotoRealmProxy::class),
value = org.parceler.Parcel.Serialization.BEAN)
#RealmClass
open class ProfilePhoto(
#SerializedName("m") open var photo : String = "",
open var id : String = "") : RealmObject()
UPDATE
RealmListParcelConverter
abstract class RealmListParcelConverter<T:RealmObject> : CollectionParcelConverter<T, RealmList<T>>() {
override fun createCollection(): RealmList<T> {
return RealmList<T>()
}
}
The approach suggested by #EpicPandaForce works. I added the RealmListParcelerConverter from the Github repository and let the annotation #Parcel(implementations = arrayOf(ProfilePhotoRealmProxy::class)) on the affected class.