Recently I worked on advance system config form field in Magento 2. I checked Braintree payment method for reference.

When I saved a value, it showing following error:

Something went wrong while saving this configuration: Notice: Array to string conversion in
E:\wamp\www\magento2\app\code\Magento\Config\Model\Resource\Config\Data.php on line 38

After print $object->getValue() array is printed with error:

screenshot 1


screenshot 2

(click screenshots to enlarge)

3 Answers 3


Add backend model for this config path. Something like


And backend model class looks like

namespace NameSpace\Module\Model\Backend
class Config  extends \Magento\Framework\App\Config\Value
    public function beforeSave()
        $data = $this->getValue();
        if (is_array($data)) {
            $this->setValue(implode(',', $data));

In Magento 2 serialize values are not directly saved in database it's using some encryption method to store serialize values. After some r & d I found these two methods in Magento 2 to convert serialize and store in db:

   protected function encodeArrayFieldValue(array $value)


   protected function decodeArrayFieldValue(array $value)

You have to set a backend_model for your field in the xml. If you don't have any special needs you can use the ArraySerialized model:


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.