質問

例外:

Error 500: Could not serialize flow execution; make sure all objects stored in 
           flow or flash scope are serializable
Servlet: grails
URI: /payment.com/grails/payment/makePayment.dispatch
Exception Message: payment.com.ValidationService$$EnhancerByCGLIB$$d0f2434f 
Caused by: Could not serialize flow execution; make sure all objects stored in 
           flow or flash scope are serializable 
Class: Unknown 
At Line: [-1] 
Code Snippet:

議論:

payment.com: project name         
payment: is the name of (domain, view, controller)
makePayment: is a webflow to make payment
ValidationService: is a service to test if credit card is valid or not

問題:
grailsプロジェクトでこのエラーが発生しました

i have a grails webflow that makes a payment, in this webflow i use grails 
command object to validate input values.
when i call the method isValid from Validation service i got this error

メモ:

i try to serialize domain class, controller, service, & command object class, 
but i couldn't solve this issue.

どんな助けでも、ありがとう

編集:

検証サービス

 package payment.com

 import java.io.Serializable;

 class ValidationService implements Serializable{

// Filter out non-digit characters
def getDigitsOnly (String s) {
  StringBuffer digitsOnly = new StringBuffer ();
  char c;
  for (int i = 0; i < s.length (); i++) {
    c = s.charAt (i);
    if (Character.isDigit (c)) digitsOnly.append (c);
  }
  return digitsOnly.toString ();
}

// Perform Luhn check
def isValid (String cardNumber) {
  String digitsOnly = getDigitsOnly (cardNumber);
  int sum = 0;
  int digit = 0;
  int addend = 0;
  boolean timesTwo = false;

  for (int i = digitsOnly.length () - 1; i >= 0; i--) {
    digit = Integer.parseInt (digitsOnly.substring (i, i + 1));
    if (timesTwo){
      addend = digit * 2;
      if (addend > 9) addend -= 9;
    }else{
      addend = digit;
    }
    sum += addend;
    timesTwo = !timesTwo;
  }
  int modulus = sum % 10;

  if (modulus == 0){
      return true
  }else{
    return false
  }
}
}

Makepaymentstep1command

package payment.com

import org.codehaus.groovy.grails.validation.Validateable;
import java.io.Serializable;
import payment.com.ValidationService;

@Validateable
class MakePaymentStep1Command implements Serializable{
ValidationService ValidationService
String cardNumber

static constraints ={
    cardNumber(blank:false, size:11..16, validator:{ val, obj->
        if (!obj.ValidationService.isValid(val)){
            return ['payment.cardNumber.invalid']
        }
        return true;
    })
}
 }

お支払い管理者

class PaymentController{
....
....
def MakePaymentFlow = {
....
    Step1{
        on('submit').to('Step1Submit')
    }
    Step1Submit{
        action {MakePaymentStep1Command cmd ->
            flow.step1Bean = cmd
            if (!flow.step1Bean.validate()){
                error()
            }
        }
        on('error').to('Step1')
        on('success'){
            flow.message = null
        }.to('Step2')
    }


....
}


}

ここでエラーが発生します:

 if (!flow.step1Bean.validate()){
     error()
 }
役に立ちましたか?

解決

あなたはaを持っています (src/groovy) あなたの中のディレクトリ grails project.あなたを置く validation Service class このディレクトリの下に、あなたの makepaymentStepCommand ようになります:

MakePaymentStep1Command

package payment.com

import java.io.Serializable;
import payment.com.Validation;

class MakePaymentStep1Command implements Serializable{
Validation validation
String cardNumber

static constraints ={
    cardNumber(blank:false, size:11..16, validator:{ val, obj->
         if (!obj.validation.isValid(val)){
            return ['payment.cardNumber.invalid']
         }
         return true;
    })
}
}

I am not sure if this works, but try it.

他のヒント

例外メッセージを見ると、ValidationServiceはシリアル化できないようです(コードを表示していないため、何が起こっているのかを推測するのは非常に困難です)。

推測では、このオブジェクトは各Paymentに依存性注入されており、フロースコープにPaymentを格納しようとしているため、PaymentServiceも格納しようとします。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top