0

I want to define a struct serializeable to json

#[derive(Serialize)]
struct Struct {
    item: SomeRuntimeType,
}

but I get this error:

error[E0277]: the trait bound `pallet_pallet::types::SomeRuntimeType: conf::_::_serde::Serialize` is not satisfied
    --> src/main.rs:150:10
     |
150  | #[derive(Serialize)]
     |          ^^^^^^^^^ the trait `conf::_::_serde::Serialize` is not implemented for `pallet_pallet::types::SomeRuntimeType`

Is there a way to derive some kind of serialization in subxt?

#[subxt::subxt(
    runtime_metadata_path = "res/metadata.scale",
    derive_for_all_types = "Debug" // <--- like adding Serialize here
)]
pub mod runtime {}

Or do I have to manually implement serialization?

1 Answer 1

1

It probably won't work to derive serde::Serialize for all types in the subxt codegen because there are some types that doesn't implement Serialize.

For individual types you can try:

#[subxt::subxt(
    runtime_metadata_path = "artifacts/metadata.scale",
    derive_for_all_types = "Clone, Debug, Eq, PartialEq",
    derive_for_type(
        path = "pallet_election_provider_multi_phase::RoundSnapshot",
        derive = "Default, serde::Serialize"
    )
)]
pub mod runtime {}

If that won't work you need to provide your own Serialize impl/add wrapper struct, replace the type with your own or something similar.

I hope it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.